Cannot load data to MySQL database with LOAD DATA INFILE

别来无恙 提交于 2019-12-07 13:35:47

问题


I am using LAMP in Ubuntu 12.04. I created a new user in MySQL (myserver@localhost) and granted ALL on a database to that user. There is a text file the permission of which is set to read for everyone. But when I try to load the data from that text file to the database, it says "Access denied for user 'myserver'@'localhost' (using password: YES)"

The query I used is:

LOAD DATA INFILE "~/text/member_info.txt" INTO TABLE member FIELDS TERMINATED BY '|';

I can think of a workaround with some loops in PHP but why doesn't the 'LOAD DATA INFILE' work?

Thanks.


回答1:


This is due the MYSQL 5.5 version you are using in Ubuntu LTS 12.04 : mysql doc

From mysql doc comment :

You can use LOAD DATA LOCAL with recent versions of PHP without recompiling PHP.

Passing 128 (the value of the CLIENT_LOCAL_FILES constant) as the fifth parameter to mysql_connect () enables LOAD DATA LOCAL on the client side.

Example: $dbh = mysql_connect($server, $user, $pass, false, 128);

For PHP 4.3 and above.

But in fact, mysql_connect() is obsolete, and I can't find a solution using mysqli.

That's why I finally use this who solve the problem.

grant file on *.* to mydatabase@localhost identified by 'myuser';

Now $mysqli->query("LOAD DATA INFILE '".$proxy_file_name_path."' IGNORE INTO TABLE mytable (myfield)"



来源:https://stackoverflow.com/questions/11014508/cannot-load-data-to-mysql-database-with-load-data-infile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!