LOAD DATA INFILE不工作 [英] LOAD DATA INFILE does not work
问题描述
我在 Ubuntu 机器上运行 MySQL 。我检查了 /etc/mysql/my.cnf
文件,它显示我的数据库临时目录:
I am running MySQL on my Ubuntu machine. I checked /etc/mysql/my.cnf
file, it shows my database temporary directory:
...
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
...
如图所示,我的MySQL服务器临时目录是 / tmp
。
As it shows, my MySQL server temporary directory is /tmp
.
我有一个 students.dat
文件,此文件的内容如下:
I have a students.dat
file, the content of this file is like following:
...
30 kate name
31 John name
32 Bill name
33 Job name
...
我复制了上述 students.dat
文件到
/ tmp
目录。然后,我运行以下命令将 students.dat
文件中的数据加载到我的数据库中的学生表:
I copied the above students.dat
file to /tmp
directory. Then, I run the following command to load the data from students.dat
file to the students table in my database:
LOAD DATA INFILE '/tmp/students.dat'
INTO TABLE school_db.students
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
(student_id, name, attribute)
但我在MySQL控制台中收到错误消息:
But I got the error message in MySQL console:
ERROR 29 (HY000): File '/tmp/students.dat' not found (Errcode: 13)
为什么mysql找不到 students.dat
文件虽然文件在mysql临时目录下?
PS
学生表格如下(在表格中已经有4条记录,然后运行 LOAD DATA INFILE ...
query):
The students table is like following (there are already 4 records in the table before run the LOAD DATA INFILE...
query):
mysql> describe students;
+-------------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+-------+
| student_id | int(11) | YES | | NULL | |
| name | varchar(255) | YES | MUL | NULL | |
| attribute | varchar(12) | YES | MUL | NULL | |
| teacher_id | int(11) | YES | | NULL | |
+-------------------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
推荐答案
查看文件未找到错误。似乎如果你指定 LOAD DATA LOCAL INFILE
应该工作(他们添加 LOCAL
关键字)
Have a look at the sixth post from file not found error. It seems if you specify LOAD DATA LOCAL INFILE
should work (They added the LOCAL
keyword)
这篇关于LOAD DATA INFILE不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!