views:

555

answers:

5

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 problem 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

A: 

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 .

Martin Hohenberg
A: 

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

easement
A: 

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.

Tom Haigh
I have added this code to my script but I am still not getting any error information. The script never seems to end!!! I have used set_time_limit(30); before the script but this doesn't seem to have any effect.
Adam
A: 

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

Michelle
A: 

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.

Ian Gregory