I’m trying to write a PHP code that will backup my SQL database daily. However, running it using a Cron Job spits out the above error in the title. My server is hosted on hostgator and its a shared server.
The dbuser has all privileges granted.
Here’s my code:
$dbhost = 'localhost';
$dbuser = 'XXXX';
$dbpass = 'XXXX';
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);
Any help would be much appreciated!
2
Answers
The following code worked for me:
your problem is the space between "-p" and $dbpass. The command mysqldump hopes "-ppassword" together (the response is "using password: no" for this).
Try: