以下MySql查询绝对没有任何内容
LOAD DATA
LOCAL INFILE 'path/to/file.csv'
REPLACE INTO
TABLE `db`.`table`
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(
`id`,
`name`
);
CSV文件如下:
"id","name"
"1","Lorem"
"2","Ipsum"
"3","Dolor"
"4","Sit"
"5","Amet"
"6","consectetur "
"7","adipisci"
"8","velit"
"9","sed"
"10","quia"
我检查了行分隔符,它是LF,文件编码是UTF-8。
我注意到如果我清空csv的第一行,或删除第一行的双引号,查询实际上会影响10行。
你知道为什么会这样吗?因为我宁愿我不必编辑第一行。
答案 0 :(得分:1)
问题在于你的Escaped By '"'
,因为第一次引用(“)遭遇,它被视为Escape
。只要摆脱它,它就会起作用。
LOAD DATA
LOCAL INFILE 'path\\to\\file.csv'
REPLACE INTO
TABLE `db`.`table`
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(
`id`,
`name`
);