将csv文件加载到mysql时出现语法错误

时间:2015-10-02 02:40:28

标签: mysql csv

编译器说语法错误接近“FIELDS TERMINATED .....”

LOAD DATA LOCAL INFILE '/Data/books.csv' 
INTO TABLE Book 
IGNORE 1 LINES
(@col1,@col2,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy) 
set Book_id=@col1,Title=@col2
FIELDS TERMINATED BY '\t' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n' 

1 个答案:

答案 0 :(得分:3)

这是因为您拥有列列表并在fields子句之前设置。当没有遇到字段行时,Mysql将使用默认值然后处理col列表,然后在遇到fields子句时抛出错误。试试这个

LOAD DATA LOCAL INFILE '/Data/books.csv' 
INTO TABLE Book 
FIELDS TERMINATED BY '\t' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n' 
IGNORE 1 LINES
(@col1,@col2,@dummy,@dummy,@dummy,@dummy,@dummy,@dummy) 
set Book_id=@col1,Title=@col2