加载csv文件

时间:2014-12-28 19:06:18

标签: mysql

我试图将csv文件加载到名为Actors的表中。 这段代码有什么问题?

LOAD DATA LOCAL INFILE 'actors.csv'
INTO TABLE Actors
FIELD TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';

2 个答案:

答案 0 :(得分:1)

你的问题在于语法。

请参阅MySQL Manual - 13.2.6 LOAD DATA INFILE Syntax。正确的语法是FIELDS而非FIELD

因此应该是:

LOAD DATA LOCAL INFILE 'actors.csv'
INTO TABLE Actors
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';

答案 1 :(得分:1)

尝试此代码,如果csv文件顶部没有标题(标题列),请忽略最后一行

LOAD DATA LOCAL INFILE 'actors.csv' 
INTO TABLE Actors
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS