简体   繁体   English

使用php进行数据库备份的mysqldump无效

[英]mysqldump using php for database backup is not working

I have written this piece of code to take my database backup. 我已经编写了这段代码来进行数据库备份。 I am using MySQL as my DB and PHP as a compiler. 我使用MySQL作为我的DB和PHP作为编译器。

<?php
$dbhost   = "localhost";
$dbuser   = "root";
$dbpwd    = "admin";
$dbname   = "mydatabase";
mysql_connect($dbhost, $dbuser, $dbpwd, $dbname) or die('Problem');
$dumpfile = $dbname . "_" . date("Y-m-d_H-i-s") . ".sql";
passthru("/usr/bin/mysqldump --opt --host=$dbhost --user=$dbuser --password=$dbpwd --all-databases > $dumpfile");
echo "$dumpfile "; passthru("tail -1 $dumpfile");
?>

The code get executed but the problem is the downloaded file is of 0KB ie there is no data in the file. 代码被执行但问题是下载的文件是0KB,即文件中没有数据。

What is the issue. 问题是什么 I have searched a lot on internet but unable to find solution for myself. 我在互联网上搜索了很多,但无法为自己找到解决方案。

If you are using Windows, place the mysqldump.exe executable in the same location as your backup script. 如果您使用的是Windows,请将mysqldump.exe可执行文件放在与备份脚本相同的位置。 That should work 这应该工作

Check permission for the directory in which your code is running. 检查运行代码的目录的权限。 It should have write permission. 它应该有写权限。

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

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