mysql - 需要 'LOAD DATA INFILE' 的指导

标签 mysql linux

我创建了一个名为“/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/

相关文章:

php - 删除具有两个重复值的值,无论它们位于哪一列

php - Codeigniter - 使用查询字符串进行路由

linux - 如何启动一个在我的 ssh session 结束时不会结束的进程?

linux - 在 heredoc 中使用时如何转义 awk 的内置变量

linux - 如何在登录一台机器后立即 ssh 进入另一台机器

mysql工作台重复键错误

php - 如何识别数据库列中的换行符

mysql - 如何从 mySql 创建和编辑数据库文件 .db?

linux - CPU 亲和性掩码(将线程放在不同的 CPU 上)

linux - 从各种文件夹中获取所有文件并使用唯一名称复制它们