我有一个我需要导入MySQL表的文件。这是我的命令
LOAD DATA LOCAL INFILE 'C:\test.csv'
INTO TABLE logs
fields terminated by '|'
LINES terminated BY '\n'
这在Windows中看起来很好,但在Linux中它只插入第一行并在日志文件中生成错误
LOAD DATA LOCAL INFILE '/home/myuser/test.csv'
INTO TABLE logs
fields terminated by '|'
LINES terminated BY '\n'
我需要在Linux中改变什么?
答案 0 :(得分:1)
我已经测试了这个" LOAD DATA INFILE"在Windows 8.1中使用mysql 5.6.17。以下是表格格式
+-----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| charactor | varchar(30) | YES | | NULL | |
| movie | varchar(30) | YES | | NULL | |
+-----------+-------------+------+-----+---------+----------------+
LOAD DATA LOCAL INFILE 'C:/Users/kaviranga/Desktop/scifi.csv' INTO TABLE scifi FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 0 LINES (charactor,movie);
这完美无缺,我使用的csv文件格式如下
"Soldier 2","Pirates of the Carribian 2"
"Soldier 1","Pirates of the Carribian 4"
不要使用如下。它可能会导致错误。
'C:\Users\kaviranga\Desktop\scifi.csv'
我已将此答案包含在内以供将来参考。
答案 1 :(得分:0)
试
LINES terminated by '\r\n'
在linux maciene中。