我创建了一个名为“/root/jyoti/test.txt”的文件,其中包含以下内容:
tail /root/jyoti/test.txt
20,'Daily','Complete'
21,'Daily','Complete'
22,'Daily','in-progress'
然后尝试按照以下查询将数据加载到 mysql 表中,例如“test”
mysql> select * from test;
+----+-----------+------------+
| id | testname | testtype |
+----+-----------+------------+
| 2 | Daily | Complete |
mysql> load data infile '/root/jyoti/test.txt' into table accounts fields terminated by ',' (id,testname,testtype);
ERROR 13 (HY000): Can't get stat of '/root/jyoti/test.txt' (Errcode: 13)
在另一篇文章中,我发现有人建议使用“加载数据本地文件”而不是“加载数据文件”,但这也因错误而失败。
mysql> load data local infile '/root/jyoti/test.txt' into table accounts fields terminated by ',' (id,testname,testtype);
ERROR 1148 (42000): The used command is not allowed with this MySQL version
我正在使用以下 MySql 版本:-
mysql -V
mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2
cat /etc/issue
Debian GNU/Linux 7 \n \l
该文件具有以下权限:
stat /root/jyoti/test.txt
File: `/root/jyoti/test.txt'
Size: 67 Blocks: 8 IO Block: 4096 regular file
Device: de00b6d1h/3724588753d Inode: 554931 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2014-06-16 12:33:34.122226597 +0530
Modify: 2014-06-16 12:33:34.122226597 +0530
Change: 2014-06-16 12:33:34.488226595 +0530
Birth: -
最佳答案
您可以使用以下方式启用加载本地文件:
--local-infile=1
当您启动 mysql 客户端时。通常默认情况下禁用它。
关于mysql - 需要 'LOAD DATA INFILE' 的指导,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24245824/