Cody Raspien
Cody Raspien

Reputation: 1835

Backup database with PHP - mysqldump

$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.

Upvotes: 1

Views: 330

Answers (2)

Dr Fred
Dr Fred

Reputation: 989

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')

Upvotes: 0

Ruslan Osmanov
Ruslan Osmanov

Reputation: 21492

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.

Upvotes: 2

Related Questions