我想使用Load data infile将CSV文件导入我的Mysql表:这是我当前的代码:
LOAD DATA INFILE '../myfile.csv'
INTO TABLE data
FIELDS
TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n' IGNORE 1 LINES (@f1,@f2...) set `f1`=@f1,...,fk=13 ;
这是csv文件的第一部分:
Timestamp,FromName,FromID,FromA,FromAID,FromURL,ToCName,ToCID,ToCTarget,ToAName,ToAID,ToAURL,UUID,Model,OS,Country,Type,Value
"2012-10-29 07:02:20","NH","4f7898654fgh02","Halloween Game","589754hj67d00021","78643609","","","","Game 1™","4f754hj67d00014","58975449","988675ffgh555f3284530","iPhone","5.1.1","GB","cpi","0.5"
这给了我一个0行插入,但如果我用IGNORE 0 LINES替换IGNORE 1 LINES,文件会成功导入(当然不会忽略第一行)。
感谢任何帮助。
答案 0 :(得分:2)
删除此行解决了问题:
ESCAPED BY '"'
工作代码:
LOAD DATA INFILE '../myfile.csv'
INTO TABLE data
FIELDS
TERMINATED BY ','
ENCLOSED BY '\"'
LINES TERMINATED BY '\n' IGNORE 1 LINES (@f1,@f2...) set `f1`=@f1,...,fk=13 ;