1

I'm working on a project and I'm playing around with the maintenance ability to dump and restore a database to work with early git development. My database will be changing a lot so I need a simple way to track this for now. Probably not the worlds best solution, but for the moment, this is a nice way to handle it.

So my problem is that I can't get mysqldump to connect.

I'm borrowing code from another post here: mysqldump via PHP

$command = "/usr/bin/mysqldump -u ".$database_user." -h ".$database_host." -p".$database_password." ".$database." > ".SERVER_PATH."data/testing.sql";

exec($command, $output, $return_var);

if($return_var !== 0) {
    $theTruth = "mysqldump for {$database_host} : {$database} failed with a return code of {$return_var}<br><br>\n\n";
    $theTruth .= "Error message was:<br>\n";
    $file = escapeshellarg("mysqldump_error.log");
    $message = `tail -n 1 $file`;
    $theTruth .= "- $message<br><br>\n\n";
    $theTruth .= "Exec: $command<br><br>\n\n";
    return $theTruth;
}

This has been returning an error message of 2: indicates "not found". The problem I'm hitting though, I can use this exact same command from the terminal and it works 100% as expected.

Edit

Using passthru instead of exec didn't reveal anything new.

I also spit out the exec command to the browser to make sure it was being processed correctly. Here's a modified version (for security purposes)

/usr/bin/mysqldump -u username -h localhost -ppass databasename > /path/to/save/every/thing/testing.sql

I'm not sure what's preventing this.

halfer
  • 19,824
  • 17
  • 99
  • 186
John Sly
  • 763
  • 1
  • 10
  • 31
  • Maybe you didn't escape the command passed to exec() and there are some special chars? – umka May 27 '15 at 18:12
  • 1
    Change to `passthru` instead of `exec` and see if you get more information back – Machavity May 27 '15 at 18:12
  • tried passthrough and it didn't give me anything new. I also checked that the command wasn't hitting some escaping issues and it all looks normal to me so far. – John Sly May 27 '15 at 18:19
  • Are you sure the path is correct and the web-server user has write permissions there? – jeroen May 27 '15 at 18:26
  • The exit code's definition from mysqldump may be a distraction, since its exit statuses don't correspond to system-defined exit codes (where 1 = operation not permitted, etc.) See http://stackoverflow.com/a/7495907/1695906 and the source code to `mysqldump.c` (.cc?) for the version of mysqldump that you are using -- which, by the way, needs to be the *newest available version* of mysqldump, since (absent any bugs) newer utilities are compatible with older servers, but (for example) mysqldump for server 5.5 doesn't work with server 5.6, while it does work the other way around. – Michael - sqlbot May 28 '15 at 11:09

0 Answers0