Mysqldump only works from the terminal run by "open site shell" menu

What issue or error are you experiencing?

I have to use system command from wordpress plugin, which should run mysqldump command from the plugin. It generates 0 byte size sql file, so I manually tested to run it from terminal, mysqldump only works at the terminal opened by “open site shell” menu from Local control panel.

I think it would be permission issue, how can we run mysqldump from any credentials especially plugin settings page from wordpress admin page?


What steps can be taken to replicate the issue? Feel free to include screenshots, videos, etc

function backup_sql_from_posts() {
global $wpdb;
global $blog_id;
$table_name = $wpdb->prefix . “posts”;
$backup_dir = sys_get_temp_dir();
$site = get_blog_details($blog_id);
$sitename = str_replace(" ", “", $site->blogname);
$backup_file = "slug_restore_backup_file
” . date(‘D-M-j-G-i-s-T-Y’) . “_” . $sitename . “.sql”;
$command = "mysqldump -h localhost -u " . DB_USER . " -p " . DB_PASSWORD . " " . DB_NAME . " " . $table_name . " > " . $backup_dir . “/” . $backup_file;

system($command);

    $path = wp_get_upload_dir();

copy($backup_dir . '/' . $backup_file, $path['basedir']  . '/' . $backup_file);

}

This function works well in manual installation servers.


System Details

  • Local Version:
    latest version
  • Operating System (OS) and OS version:
    Linux Mint jammy

Local Logs

Attach your Local Logs here (Help Doc - Retrieving Local’s Log)


Security Reminder
Local does a pretty good job of scrubbing private info from the logs and the errors it produces, however there’s always the possibility that something private can come through. Because these are public forums, always review the screenshots you are sharing to make sure there isn’t private info like passwords being displayed.

Hi @bluenote

Sorry I’m not quite following so I might need some clarification here.

What WordPress plugin are you trying to use?

Are you needing to export the Database?

Have you utilized the Adminer tool within our Local app?

Plugin is only one that I am developing and testing. It has code the above to run mysqldump command. I would like to export database table and the command works from Open site shell menu from Local control panel, its terminal works, but regular terminal it does not. I think permissioni is granted from Open site shell menu by Local, not for regular terminal ^^

Local app’s Adminer is not for plugin working, I would like to dump MySQL table from plugin page I am making ^^ If there is way to elevate user permission as in Open site shell menu’s terminal, it would be solved, I don’t have idea about this.

I think Local is very great tool to shortens the way to make wordpress development environment wth convenient ways, I appreciate the care of developing and providing for free too.

Many people would use my plugin in this tool, so I would like to know how to resolve my issue.

If you have any ideas, please let me know ^^;;

I think ~/.config/Local/ssh-entry directory’s *.sh files can be used for constructing user permission and environment variables, if I pass the command ‘~/.config/Local/ssh-entry/filename.sh && mysqldump -options’ to PHP function system();, is this predicted to be working?

One more question is that how we can get the right .sh file in current wordpress site configuration?

I have figured out other way allowed, such that rather than using mysqldump, using SQL commands by wordpress API and from the query result assembly into text file.

I think for security reason, which .sh file is for current instance of wordpress site is hardly unleased so figured out the way at the above.

Thank you for providing convenient app for wordpress setup ^^

1 Like

Hi @bluenote

We’re glad you were able to get somewhere with this! Thank you for your patience and communication with us. I was waiting on some follow up with the Devs to see if they could provide some more insight but they’ve had to prioritize some other end of year work :slight_smile:

If you have any other questions or concerns don’t hesitate to reach back out. We are always happy to help!

This topic was automatically closed 36 hours after the last reply. New replies are no longer allowed.