开发者

mysqldump and wamp

开发者 https://www.devze.com 2022-12-09 15:38 出处:网络
Update: Finally got this thing working but still not sure what the problem was. I am using a wamp server that I access through a networked folder.

Update: Finally got this thing working but still not sure what the problem was. I am using a wamp server that I access through a networked folder.

The p开发者_开发技巧roblem that still exists is that to execute the mysqldump I have to access the php file from the actual machine that is being used to host the WAMP server.

End of update

I am running a wamp server and trying to use mysqldump to backup a mysql database I have. The following is the PHP code I am using to run mysqldump.

exec("mysqldump backup -u$user -p$pass > $sql_file");

When I run the script the page just loads inifnately and the backup is not created.

A blank file is being created so I know something is happening.

Extra info:

* exec() is not disabled
* PHP is not running in safe mode

Any ideas??

Win XP, WAMP, MYSQL 5.0.51b


mysqldump is likely to exceed the maximal time php is supposed to run on your system. Try using the command in cmd or increase the max_execution_time in your php.ini .


Are you sure $pass is defined and doesn't have a space character at the start?

If it wasn't, mysqldump would be waiting for command line entry of the password.


I had the same thing happen a while back. A co-worker pointed me to the MySQL GUI tools and I have been making backups with that. The Query Browser that comes with it is nice, too.

MySQL GUI tools


It might help to look at the stderr output from mysqldump:

$cmd = "mysqldump backup -u$user -p$pass 2>&1 > $sql_file";
exec($cmd, $output, $return);
if ($return != 0) { //0 is ok
    die('Error: ' . implode("\r\n", $output));
}   

Also you should use escapeshellarg() if $user or $pass are user-supplied.


I've also struggled with using the mysqldump utility. I few things to check/try based on my experience:

  • Is your server set up to allow programs to run programs with an exec command? (My webhost's server won't let me.) Test with a different command.

  • Is the mysqldump utility installed? Check with whereis mysqldump.

  • Try adding the optimize argument --opt

0

精彩评论

暂无评论...
验证码 换一张
取 消