Home > Software engineering >  MySQL Dump file is empty
MySQL Dump file is empty

Time:10-22

I try to create backup of my database, it creates file.sql, but it is empty, how can I solve it ?

$backup_file = $filename .'_'. date("Y-m-d-H-i-s") . '.sql';

$command = "mysqldump --opt -h $HostName -u $HostUser -p $HostPass --all-databases". "$DatabaseName > $backup_file";

system($command);

CodePudding user response:

there is no space after --all-databases

$backup_file = $filename .'_'. date("Y-m-d-H-i-s") . '.sql';

$command = "mysqldump --opt -h $HostName -u $HostUser -p $HostPass --all-databases ". "$DatabaseName > $backup_file";

system($command);

CodePudding user response:

the first problem you got o told you in the comment --all_databases' already adds all databases, so no need for adding more databases

The second is you have a space between -p and your password, so mysqldump things it is a database, removing the space will solve that problem.

If you have functions or procedures you need to add more parameters like -routines

--Opt isn't need as it is enabled by default

$backup_file = $filename .'_'. date("Y-m-d-H-i-s") . '.sql';

$command = "mysqldump -h $HostName -u $HostUser -p$HostPass -routines --all-databases > $backup_file";

system($command);
  • Related