开发者

How to export full mysql database with php script...? Problem in using 'mysqldump'

i am using this command to backup my full mysql database..

$backupFile = $dbname . date("Y-m-d-H-i-s") . '.sql';
$command = "mysqldump -h$hostname -u$username -p$password $dbname > $backupFile";
system($command);

I am getting blank file. And i am using XAMMP on windo开发者_Go百科ws. I have already used exec() but also getting blank file. And but on shell it has successfully done. Whats wrong in this code.


The best thing you can do is check what is going wrong. You might even want to check outside of PHP to see what you are doing. So echo your $command, and look at it, see if it looks correct. Then use it on the commandline, see if you can get it to work.

Possible attention points:

  • Do you have any 'strange' characters (like &) in your password? You might need to escape them
  • Is the mysqldump command available? (is it in your PATH, or in the dir where you are running this from
  • Are you allowed to do any system/exec commands at all?
  • Is the user that runs your php code (apache?) allowed to do this command?
  • Is the user that runs this code allowed to write in this directory?

To test your current command, you might want to do this: - replace your system command with an echo: echo $command; - run the script and copy the command you see there. - Open a terminal. (start->run->"cmd") - goto the dir where your script is / runs. - paste /type the command. - check your result.

I do not know what happens when you do not have a password, but still supply the -p option. It might try and ask for a password anyway, as you've indicated you want to enter a password, but have not provided it. I do not know this for sure, that's why you might want to check it. (@wimvds confirms in the comment: if you supply a -p and no password, you'll get a "password: " dialog.)

In the commandline you can check what command you need to type to get the mysqldump to work. If that's ok, then make sure your script actually issues that command. Then test again with the script.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜