简体   繁体   English

MysqlDump返回一个空的数据库备份文件

[英]MysqlDump Return a Empty database backup file

I use this code for download a backup of MySql database but it download a empty file. 我使用此代码下载MySql数据库的备份,但它下载了一个空文件。 Please also guide for restore this backup. 另请指导还原此备份。

<?php
//connect to database
include'connect.php';
$backupFile = $dbname . date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump -h$hostname -u$username -p$password $dbname > $backupFile";
system($command);
?>

Replace system with echo to show the generated command, and execute it on the command line manually. echo替换system以显示生成的命令,然后在命令行上手动执行它。 Errors are usually shown on STDERR, which isn't caught by the system call, and if you get an empty output that means it couldn't output anything. 错误通常显示在STDERR上,但system调用无法捕获该错误,如果输出为空,则表示它什么也不能输出。 Fix the error and then fix your code. 修复错误,然后修复代码。 I'd also use passthru instead of system . 我也将使用passthru而不是system

To restore the backup afterwards use (from the commandline): 要在以后还原备份,请使用(从命令行):

mysql -u<user> -p <database> < myfile.sql

Your variables are sticked to the options. 您的变量将遵循选项。 Try to change this: 尝试更改此:

$command = "mysqldump -h$hostname -u$username -p$password $dbname > $backupFile";

To this: 对此:

$command = "mysqldump -h $hostname -u $username -p $password $dbname > $backupFile";

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

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