我使用 Scalding 的默认Csv
写入器(指定p
要写入的路径的参数,而不是如何写入 CSV 数据的任何其他参数)生成了一个 CSV 文件,我希望将其导入 MySql。我在导入时遇到问题。
加载数据的示例查询:
CREATE TABLE `example_table` (
`a` varchar(255) DEFAULT NULL,
`b` varchar(255) DEFAULT NULL,
`c` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
LOAD DATA LOCAL INFILE '~/example.csv'
INTO TABLE example_table
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
(a,b,c)
示例数据(即~/examples.csv
):
row1,this is neither quoted nor enclosed,"This is quoted, and contains a comma"
row2,"this is enclosed","This is quoted, and contains a comma"
row3,""this"" is quoted at the start,"This is quoted, and contains a comma"
row4,"""this"" is quoted at the start and enclosed","This is quoted, and contains a comma"
当我使用数据文件运行查询时,结果表是(请原谅格式,我无法弄清楚如何在这里很好地制作表格):
row1|this is neither quoted nor enclosed|This is quoted, and contains a comma
row2|this is enclosed|This is quoted, and contains a comma
row3|"this" is quoted at the start,"This is quoted, and contains a comma|NULL
row4|"this" is quoted at the start and enclosed|This is quoted, and contains a comma
第 3 行格式不正确,如果该字段等于,Scalding 如何输出 CSV "this" is quoted at the start
(即,它在字符串的开头有引号,并且不包含字段分隔符,在这种情况下,它看起来像第 4 行)。
有没有办法使用 MySql 中的FIELDS TERMINATED BY
,OPTIONALLY ENCLOSED BY
, etc 选项让它正确导入字段?