我正在尝试使用php备份mysql数据库。 我尝试了下面的代码:
<?php
$dbhost = 'my_host';
$dbuser = 'my_user';
$dbpass = 'my_pass';
$db = 'my_dbname';
$conn = mysql_connect($dbhost, $dbuser, $dbpass, $db);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$table_name = "my_table";
$backup_file = "/tmp/my_table.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
mysql_select_db($db);
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not take data backup: ' . mysql_error());
}
echo "Backedup data successfully\n";
mysql_close($conn);
?>
但是我收到了这个错误:
&#34;无法进行数据备份:用户访问被拒绝&#39; my_user&#39; @&#39;%&#39; (使用密码:是)&#34;
你能帮助我吗?谢谢!答案 0 :(得分:0)
尝试
<?php
$dbhost = 'my_host';
$dbuser = 'my_user';
$dbpass = 'my_pass';
$db = 'my_dbname';
$conn = mysql_connect($dbhost, $dbuser, $dbpass, $db);
if(! $conn ) {
die('Could not connect: ' . mysql_error());
}
$table_name = "my_table";
$backup_file = "/tmp/my_table.sql";
$sql = "SELECT * INTO OUTFILE '$backup_file' FROM $table_name";
// set current db with connection resource
mysql_select_db(db, $conn);
$retval = mysql_query( $sql, $conn );
if(! $retval ) {
die('Could not take data backup: ' . mysql_error());
}
echo "Backedup data successfully\n";
mysql_close($conn);