php程序备份mysql数据库,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 );

When I run it from the shell terminal, I get this:

[stingray]$ php /[ABSOLUTE

PATH]/db_backup.php

Enter password: [I INPUT 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

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.

Thanks.

解决方案

The syntax for the password flag is different. Remove the space after the -p flag and give it another shot.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值