简体   繁体   中英

php / mysql access denied with select into outfile

I have the following php code:

<?php

$hostname="db.";
$database="db..";
$username="db...";
$password="pw...";
$mysql = mysql_connect($hostname, $username, $password);

if(!$mysql) 
 echo 'Not conneted to the database...' . mysql_error() ;
else
 echo 'Connected to the database...' ;

// select the appropriate database
$mysqldb = mysql_select_db( $database );
if(!$mysqldb) 
 die('Could not select the database...'  . mysql_error());
else
 echo '<br /><br />Connected to database...<br /><br />' ;

$chk_table_access = 'select * from table_name where 1';
$chk_access = mysql_query($chk_table_access);
echo $chk_table_access . '<br /><br />';
if (!$chk_access) 
 echo 'Could not access table: ' . mysql_error() ;
else
 echo 'Table was accessed..<br /><br />' ;

$backup = 'SELECT * INTO OUTFILE "result.csv" FIELDS TERMINATED BY "," OPTIONALLY     ENCLOSED BY ';
$backup = $backup . "'" . '"' . "'" ;
$backup = $backup . ' FROM cities WHERE 1';
echo $backup . '<br /><br />';
$bk_success = mysql_query($backup);
if (!$bk_success)
 echo 'The backup was not successful. Reason: '  . mysql_error();
?>

The program runs fine on localhost, but when I run it from my web site I get the following error: Access denied for user 'dbo????????'@'%' (using password: YES). The web help is not much help.

I do get the "Table was accessed.." message so I'm accessing the table okay. I do frwite to the directory every day without errors. I understand why it doesn't work in phpMyAdmin. I'm a little stumped. It's also the first question I've asked on this forum although I come here often for help. You guys (ladies included) rock. Thanks in advance, Steve

Your MySQL user apparently lacks the FILE privilege .

Does the MySQL server run on the same machine as the web server? If both servers run on different machines, you can stop right here: Even with FILE privilege, the output file would be created on the database server (and would probably inaccessible from the web server).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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