将csv文件导入mysql:十进制值不正确:'“0.5'

时间:2016-11-09 13:35:43

标签: mysql

有人能指出我做错了什么: csv文件:

weight,student,price
0.5,4,2.3

命令:

LOAD DATA INFILE 'prices.csv'
            INTO TABLE prices
            FIELDS TERMINATED BY ','
            LINES TERMINATED BY '\n'
            IGNORE 1 ROWS;

错误:

Incorrect decimal value: '"0.5' for column 'weight' at row 1

1 个答案:

答案 0 :(得分:1)

您的文件中可能有一个封闭(或转义)字符(我不知道您的真实文件)。尝试指定ENCLOSED BY

LOAD DATA INFILE 'prices.csv'
INTO TABLE prices
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;

如果这不起作用,请尝试使用ESCAPED BY

LOAD DATA INFILE 'prices.csv'
INTO TABLE prices
FIELDS TERMINATED BY ',' ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;