CSV文件到MySQL数据库

时间:2012-02-11 03:07:32

标签: mysql csv mysqldump

我有以下格式的CSV文件:

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

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"

我想将所有数据加载到MySQL中。我尝试了以下命令:

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

我收到以下错误:

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

我的代码或CSV有什么问题?

1 个答案:

答案 0 :(得分:3)

FIELDS TERMINATED BY'","'更改为','