将csv加载到mysql中

时间:2014-07-27 12:28:43

标签: mysql csv

我有以下代码将csv加载到mysql中。

SET @count = 0;
LOAD DATA INFILE 'TELE_AFC_03.03.2014.csv'
INTO TABLE failure_report.master_entry
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"'
LINES TERMINATED BY '\n'  
ignore 2 rows
(@sno,@var1,line,section,station,system,sub_system,equipment,sub_equipment,failure_time,rectified_time,duration,failure_description,rectification,lmd,origin,attended_by,reported_by,urr)
set id = (@count :=@count+1), failure_date =STR_TO_DATE(@var1, '%c/%e/%Y');

它适用于某些文件,但对于某些csv,它会出错

Row 1 was truncated; it contained more data than there were input columns

虽然所有文件都有相同数量的列。 这个csv给出了错误 http://speedy.sh/bSDTE/TELE-AFC-05.03.2014.csv
而这个csv工作正常,虽然两个都有相同的列 http://speedy.sh/h4cVt/TELE-AFC-03.03.2014.csv

0 个答案:

没有答案