我试图将csv文件加载到名为Actors
的表中。
这段代码有什么问题?
LOAD DATA LOCAL INFILE 'actors.csv'
INTO TABLE Actors
FIELD TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"';
答案 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