PHP脚本备份MySQL数据库 [英] PHP Script to Backup MySQL Database
问题描述
我正在尝试编写PHP脚本来备份MySQL数据库:
I'm trying to write a PHP script to backup a MySQL database:
if ( $db_resource = mysql_connect($db_server, $db_username, $db_password, $db_newlink) )
{
if ( mysql_select_db( $db_name, $db_resource ) )
{
$backupFile = $db_name."_".date( "Y-m-d-H-i-s" ).".gz";
$command = "mysqldump --opt -h ".$db_server." -u ".$db_username." -p ".$db_password." ".$db_name." | gzip > ".$db_save_dir."/".$backupFile;
system( $command );
}
}
mysql_close( $db_resource );
当我从shell终端运行它时,我得到了:
When I run it from the shell terminal, I get this:
[stingray] $ php/[ 绝对 PATH ]/db_backup.php
[stingray]$ php /[ABSOLUTE PATH]/db_backup.php
输入密码:[ 我输入密码 ]
Enter password: [I INPUT PASSWORD]
mysqldump:得到错误:1044:访问 拒绝用户 '[ USERNAME ]'@'208.113.128.0/255.255.128.0' 到数据库"[ PASSWORD ]"时 选择数据库
mysqldump: Got error: 1044: Access denied for user '[USERNAME]'@'208.113.128.0/255.255.128.0' to database '[PASSWORD]' when selecting the database
好吧,现在我真正不明白的是为什么它调用数据库作为我的密码.如果我将Web浏览器指向该文件,则该文件运行正常.有人知道我应该做什么吗?就我个人而言,我真的不在乎它是否是PHP,Python,CGI等,只要它可以在Apache服务器上运行即可.
Okay, now what I really don't understand is why it is calling the database as my password. If I point my web browser at the file, it runs just fine. Does anyone know what I should be doing? Personally, I really don't care if it's PHP, Python, CGI, etc., just so long as it can run on an Apache server.
谢谢.
推荐答案
密码标志的语法不同.删除-p标志后的空格,然后再进行拍摄.
The syntax for the password flag is different. Remove the space after the -p flag and give it another shot.
这篇关于PHP脚本备份MySQL数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!