0

I ran below SQL query against my MySQL database:

load data local infile '/tmp/ad_packs.csv' 
into table ad_packs 
fields terminated by ',' 
enclosed by '"' 
lines terminated by '\n' 
(company_name,pack_size,remaining,ad_pack_purchase_officer,advertising_contact_officer,updated_ad_pack,email,phone,website,note,organisation_id,categories,modified)

This seems to insert only one row and I already checked the csv and it has heading so it only inserts the first row which is the header.

Is there a reason why?

2
  • If you are using Unix or have access to Unix commands, try running the command "od -a" on the data file. ("od" stands for octal dump.) It will show you exactly the character(s) used to terminate the lines. Is there a similar command in Windows? Commented May 14, 2012 at 13:33
  • Please upload the first 5 lines of your csv file Commented May 14, 2012 at 14:02

4 Answers 4

2

Belated answer, I have just had this problem myself; Tried everything. The solution for me was to set AUTO_INCREMENT against my id field, and voila in came the records.

Sign up to request clarification or add additional context in comments.

Comments

1

Are you sure sure your lines are terminated by "\n"? Try "\r\n";

4 Comments

Actually the csv doesn't have " quotation marks enclosed with values. Is that a reason why? If so, can we still import without those?
Your import statement does say "enclosed by '"' " so that could very well be the problem
I tried taking it out but it still imports only one row. Is there an easy way to enclose this quotation on values?
If you're using PHP i'd recommend looking at the csv functions for importing the data. They're handle all of the issues for you.
1

Try to look into your primary key of table. If no problem with the '\n', '\r\n' issue, it is very likely the first row and second row in your csv file share the same primary key.

Comments

0

Had the same issue just recently and used the od -c command on the csv file. It showed that \r was being use for the line breaks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.