我是一个CSV文件,其值可能是逗号作为值的一部分
"09200, France, Paris", "Tower ""Olivia"""
"09200, Spain, Barselona", Shop - perfect
但是,一旦我导入数据,它就会破坏4列的值(基于行中的逗号数)。我做错了什么?请参阅下面的导入命令。
LOAD DATA LOCAL INFILE '~/Downloads/file.csv' INTO TABLE my_table CHARACTER SET utf8 FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (@col1,@col2) set address=@col1,name=@col2;
答案 0 :(得分:2)
在查询中添加ENCLOSED BY
子句:
LOAD DATA LOCAL INFILE '~/Downloads/file.csv'
INTO TABLE my_table
CHARACTER SET utf8
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(@col1,@col2) set address=@col1,name=@col2;