我有一个CSV文件,其中一列包含下一个数据:
"2015-01-01",
...
...
"2015-03-27"
我用这种方式创建了mysql表:
CREATE TABLE `my_tbl` ( `id` int(11) NOT NULL AUTO_INCREMENT, `date` DATE NOT NULL, PRIMARY KEY (`id`) );
我正在尝试使用下一个命令插入数据:
LOAD DATA INFILE '/tmp/myFile.csv' INTO TABLE my_tbl FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' (@col1) set date=@col1;
问题: 检查my_tbl时,我发现所有记录都是' 0000-00-00'
答案 0 :(得分:0)
发现差异:
[..snip..] BY '\n' (@col1) set date=@co1;
^---------------^
答案 1 :(得分:0)
看来我应该添加 FIELDS ENCLOSED BY' \"' 。所以LOAD查询应该是这样的:
LOAD DATA INFILE '/tmp/myFile.csv' INTO TABLE my_tbl FIELDS ENCLOSED BY '\"' LINES TERMINATED BY '\n' (@col1) set date=@col1;
用户@Marc B的Tnx提示