3

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.

4

1 回答 1

1

这是由于您在 Ubuntu LTS 12.04 中使用的 MYSQL 5.5 版本:mysql doc

来自 mysql 文档评论:

您可以将 LOAD DATA LOCAL 与最新版本的 PHP 一起使用,而无需重新编译 PHP。

将 128(CLIENT_LOCAL_FILES 常量的值)作为第五个参数传递给 mysql_connect() 可以在客户端启用 LOAD DATA LOCAL。

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

适用于 PHP 4.3 及更高版本。

但其实mysql_connect()已经过时了,用mysqli也找不到解决办法。

这就是为什么我最终使用这个解决问题的人。

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

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

于 2012-11-16T18:45:51.503 回答