MySQL only imports a single row from CSV

2019-03-28 06:05发布

问题:

Development machine is a Mac. I'm having some trouble importing more than a single line from a CSV into Mysql. Here is my SQL statement:

LOAD DATA LOCAL INFILE 'test.csv' 
INTO TABLE students
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(pita, dob, name, grd, asst, loc);

It runs fine, but only one record is imported. Any idea where I'm going wrong?

回答1:

Check the line endings:

head -n2 sql.sql | hexdump -C

but the most common problem, the line terminator isn't what you'd expect, try:

LINES TERMINATED BY '\r'