1
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.gz';
$command = "mysqldump --opt -h $dbhost -u $dbuser -p $dbpass $dbname | gzip > $backupFile";
system($command);

My backup file ends up being an empty zero byte file.

My authentication and connection details are correct.

I enabled error reporting - no errors.

Server is running PHP 5.6.

1
  • catch errors with proc_open(), or redirect stderr to some file: mysqldump ... | gzip > file 2>error.log Commented May 5, 2016 at 9:28

2 Answers 2

2

According to mysqldump documentation, you shouldn't put space between -p and password:

· --password[=password], -p[password]

The password to use when connecting to the server. If you use the short option form (-p), you cannot have a space between the option and the password. If you omit the password value following the --password or -p option on the command line, mysqldump prompts for one.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I removed the space and it worked: $command = "mysqldump --opt -h $dbhost -u $dbuser -p$dbpass $dbname | gzip > $backupFile";
0

When calling mysqldump from PHP you may need to write the executable full path (ie : '/usr/local/mysql-5.1.52-osx10.6-x86_64/bin/mysqldump' instead of 'mysqldump')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.