简体   繁体   中英

Importing a CSV in MySQL. Only every second line is imported

i want to import a csv table into mysql with this command:

LOAD DATA LOCAL INFILE 'C:/Users/user/Desktop/SA01505.csv' INTO TABLE hks.orc CHARACTER SET 'utf8' COLUMNS  TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'  ESCAPED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES (@var1,@var2,@var3,`TI 41-40`,`TI 41-41`,`TI 41-42`,`TI42-40`,`TI 42-41`,`TI 42-42`,`TI 42-43`,`TI 42-43.2`,`TI 42-44`,`TI 42-45`,`TI 42-46`,`TI 42-47`,`PI 42-71`,`PI 42-72`,`PI 42-73`,`PI 42-75`,`FI 42-90`,`TI 43-40`,`TI 43-41`,`TI 45-40`,`TI 45-41`,`TI 47-41`,`TI 47-42`,`TI 47-43`,`TI 47-44`,`LI 42-61`,`SI 44-81`,`QI 46-22`,`UV 41-10_Soll`,`UV 41-10_Ist`,`UV43-10_Soll`,`UV43-10_Ist`,`Tc2`,`Tc3`,`Tc4`) 
SET Datum = STR_TO_DATE(CONCAT(@var2,@var3),'%Y/%m/%d%k:%i:%s');

This code works, but imports only every second line, although every line is terminated with "\\n" (i checked this with an hex-editor)

I'd guess that the problem is here: OPTIONALLY ENCLOSED BY '"' ESCAPED BY '"' . This is biting each other.

In the first line imported the last " of the enclosed column escapes the \\n of the line terminator. Therefore always two lines are treated as one and you probably don't see the "second line" in the imported data because the data gets truncated.

Remove the ESCAPED BY '"' clause and see if it works. If it works but you need it to properly import your data, you'll have to work on your data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM