Cannot get mysqldump to run from localhost

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
User avatar
freshnet
php-forum Active User
php-forum Active User
Posts: 363
Joined: Tue Feb 22, 2011 8:19 am
Location: Canada

Sat Jan 20, 2018 8:54 am

[back after some time off!]

On my production websites, I have some code that runs via a cron job to backup the databases. This is working fine, and I want to set up the same thing (but more complex) on my own machine. The exec command that I have is fine, because when I echo it back and run it from command line (in the same directory as the script) it works. However when I run the exec command from php, it appears to do nothing (no backup, no error). Any ideas?

here's the code. As I mentioned, if I output the variable and run it in terminal, it works. the same command on my production server works. I've also tested running an exec("whoami") just to make sure exec is working in my php, which it is. I have error reporting set to E_ALL. The php user has read/write permissions to the directory I'm using. I don't have safe mode on or any disabled_functions set. Any ideas?

Code: Select all

$command = "mysqldump --log-error='error.txt' --user=$username --password=$password 
                        --single-transaction --host=$host --databases $database --result-file=$filePath";
                        exec($command, $return);
Step one with troubleshooting queries is always to echo back the full query and run it to see if you get an error.
If you are asking for help with code, please provide the code, the expected result and the actual result, or you will likely not get any replies.

Post Reply