mysql循环load data,无法使用LOAD DATA INFILE将数据加载到MySQL数据库

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.

解决方案

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)"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值