简体   繁体   English

使用PHP备份数据库-mysqldump

[英]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. 服务器正在运行PHP 5.6。

According to mysqldump documentation, you shouldn't put space between -p and password: 根据mysqldump文档,您不应在-p和密码之间放置空格:

· --password[=password] , -p[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. 如果使用简短选项格式(-p),则选项和密码之间不能有空格。 If you omit the password value following the --password or -p option on the command line, mysqldump prompts for one. 如果在命令行上--password或-p选项后省略了密码值,则mysqldump会提示输入一个。

从PHP调用mysqldump时,您可能需要编写可执行文件的完整路径 (即:“ / usr / local / mysql-5.1.52-osx10.6-x86_64 / bin / mysqldump ”,而不是“ mysqldump ”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM