Empty files generated from running `mysqldump` using PHP

To put it in plain english, make sure to use the following options (all of them).
--user=USERNAME
--host=localhost
--password=****

The next non-option phrase should be your database name. If the command is followed by another non-option phrase, it will be treated as table names.

$command="mysqldump --xml --host=localhost --user=USERNAME --password=***** DBNAME > XMLTABLE.xml";
system($command);

I believe there are no spaces between -u and the actual username.

host: localhost user: peter password: pwd

would become:

-hlocalhost -upeter -ppwd

This is how I have done it - output is with maximum gzip compression:

<?php exec("/usr/bin/mysqldump --opt --host=MYSQLHOSTNAME --user=MYSQLUSER --password=PASSWORD DATABASENAME | gzip -v -9 >DATABASENAME.". date("Y-m-d_H-i-s") . ".sql.gz");?>

Remove the space between -p and the password. If it didn't work, try to remove the quotes from the password

from MySQL documentation:

If you use the short option form (-p), you cannot have a space between the option and the password.

however, it is fine to have space with -h and -u options

Tags:

Mysql

Php