CanCeylan
CanCeylan

Reputation: 3010

CSV File to MySQL Database

I have a CSV file in the following format:

"id","code","date","address","complete_url"

Example data from the CSV:

"144003286","ICXT","20100104","NJ","http://www.orhancanceylan.com"
"144003286","SEED","20100104","NY","http://www.erbileren.com"
"144003286","ANX","20100104","CA","http://www.foursquareme.com"
"144003286","AIG","20100104","NJ","http://www.orhancanceylan.com"

I want to load all of the data into MySQL. I tried the following command:

LOAD DATA LOCAL INFILE 'C:\\Users\\pb\\Documents/data.csv' 
INTO TABLE new_table
FIELDS TERMINATED BY '","' ENCLOSED BY '"'
LINES TERMINATED BY '\n'

And I received the following error:

1265 Data truncated for column 'id' at row 1
 1261 Row 1 doesn't contain data for all columns
 1261 Row 1 doesn't contain data for all columns
 1261 Row 1 doesn't contain data for all columns
 1261 Row 1 doesn't contain data for all columns
 Records: 1  Deleted: 0  Skipped: 0  Warnings: 5    3.620 sec

What is wrong with my code or CSV?

Upvotes: 2

Views: 4993

Answers (1)

Joe
Joe

Reputation: 15802

Changed FIELDS TERMINATED BY from '","' to ','

Upvotes: 3

Related Questions