LOAD DATA INFILE only 1 record inserted
Asked Answered
S

5

5

I have a csv file that I'm trying to import via the command line. But only 1 row is being inserted. They are comma separated values. I'm on a Mac using Excel Mac. I save as a csv file. How can I tell if the lines are terminated by \r or \n or both? Here is the code I used:

LOAD DATA LOCAL INFILE '/Users/eric/Documents/contacts_test.csv' INTO TABLE `contacts_tmp` FIELDS TERMINATED BY ',' ESCAPED BY '\\' LINES TERMINATED BY '\n' (clientid,contactid,title,fname,mname,lname,suffixname,salutation,occupation,employer,home_addr1,home_addr2,home_city,home_state,home_zip,home_county,primary_addr1,primary_addr2,primary_city,primary_state,primary_zip,primary_county,work_addr1,work_addr2,work_city,work_state,work_zip,work_county,email,phone_home,phone_mobile,phone_work,fax,phone_other,codes);

thanks

Slothful answered 7/2, 2010 at 1:38 Comment(1)
Command as such doesnt have any problem. Did you check the command in Windows or Linux?Halcomb
S
6

Had the same issue, LINES TERMINATED BY '\r' did the job.

Scherzando answered 19/11, 2013 at 6:4 Comment(0)
G
5

I would just recommend trying the same command with ... LINES TERMINATED BY '\r\n' ... and see if you have better luck.

Gavrielle answered 7/2, 2010 at 1:51 Comment(2)
Mac text files are generally ended with '\n' nowadays. An older class app might still use '\r' but that's pretty rare these days.Bemused
its not working i used this content in csv sodocumentation.net/mysql/topic/2356/load-data-infileDarlleen
A
3

If in your file the line is terminated by the ,, then you should add LINES TERMINATED BY ',\r\n'.

This will solve your issue as it did with mine.

Adigranth answered 16/5, 2012 at 8:37 Comment(0)
D
1

Mac text files usually end in \r but you can find this out by using a hex editor and seeing what the lines end with.

Distort answered 7/2, 2010 at 2:1 Comment(3)
'\n' is more common nowadays. See comment above.Bemused
Thanks! Got the same problem and this one solved the problem!Lachman
I read somewhere that it was Mac OS 9 or older that uses '\r'. Mac OS X uses '\n'.Pipsqueak
T
1

Just try removing LINES TERMINATED BY '\n' altogether from your query.

If you don't specify a delimiter, MySQL fill figure it out automatically.

Triune answered 8/2, 2010 at 13:53 Comment(1)
If you specify no FIELDS or LINES clause, the defaults are the same as if you had written this: FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\' LINES TERMINATED BY '\n' STARTING BY '' ---- that is what the mySQL documentation says.Pipsqueak

© 2022 - 2024 — McMap. All rights reserved.