Tao
Tao

Reputation: 11

MySQL loads CSV file but without double quotes?

I am using MySQL to load a CSV file, but there is no quotes for the string column, so I only get the first letter of the value.

1,Toyota Park,Bridgeview,IL,0
2,Columbus Crew Stadium,Columbus,OH,0
3,RFK Stadium,Washington,DC,0

After I use the code here, I got this:

LOAD DATA LOCAL INFILE 'C:\\Users\\tank\\Desktop\\test.csv'
INTO TABLE test
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'
IGNORE 0 ROWS;

and I had this table:

+---------------------------------------------+
| ID, Studios, City, State, Open              |
+---------------------------------------------+
| '1', 'T', 'B', 'I', '0'                     |
| '2', 'C', 'C', 'O', '0'                     |
| '3', 'R', 'W', 'D', '0'                     |
+---------------------------------------------+

Upvotes: 1

Views: 1295

Answers (1)

DPS
DPS

Reputation: 1003

You should use enclosed by:

LOAD DATA LOCAL INFILE 'C:\\Users\\tank\\Desktop\\test.csv'
INTO TABLE test
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'
ENCLOSED BY '\"'
ESCAPED BY '\"'
IGNORE 0 ROWS;

Upvotes: 3

Related Questions