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

link|improve this question
2  
Why do you want to call this from PHP? – Dan Carley Oct 21 '09 at 14:07
How big are your tables? PHP has time constraints on how quickly it can run when launched from Apache... Regardless you should see $sql_file being created and growing. Are you referring to a "blank file" as $sql_file? It should not be blank. – Kyle Smith Oct 21 '09 at 14:20
Seconded - I wouldn't do this from PHP. – Randolph West Oct 21 '09 at 14:28
It needs to be done in PHP as it needs to be set up as a cron job in the future. The tables are quite small, I have 12 tables in the database. 10 have less than 100 rows and the other two have just over a 1000 each. The file is being created but the contents of the file is empty. If not with PHP how would you does this. Thanks – Adam Oct 21 '09 at 14:32
It needs to be set up as a cron job in the future so you have to use PHP exec()? Cron jobs in Windows can be commands with absolute or relative paths in a text .cmd file, the same goes for unix where you chmod +x the file and add it to crontab. There is no requirement to use PHP here. – Kyle Smith Oct 21 '09 at 15:47
feedback

3 Answers

1) In WampServer, default user is "root" and default password is empty. So $pass == "", and your command line make mysqldump prompt for a password. You may check if $pass is empty, and if true, don't use -p parameter.

2) Using "mysqldump backup", mysqldump tries do backup the database named "backup". You should replace "backup" with your database name.

3) Is mysqldump.exe found? If not, you will have to specify its path.

A quick method to check output of a command :

exec("mysqldump", $output=array());
foreach ($output as $line) {
    echo $line;
}
link|improve this answer
feedback
  1. try adding full path for mysqldump.exe
  2. ini_set('max_execution_time', 0); in your php file (be really careful because it can eat lot of resources
  3. if doesnt work, try dumping a smaller db (even empty one)
link|improve this answer
feedback

Try with a

mysqldump dbname -u root -p=blabla

Instead of

michael@web01:/$ mysqldump cms -u root -p blabla

The latter will ask for a password, and let you wait for a long time.

Hope this helps.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown