导入csv日期更改为0000-00-00

时间:2014-04-15 14:32:56

标签: sql phpmyadmin

LOAD DATA INFILE 'filename.csv' INTO TABLE table_name 
FIELDS TERMINATED BY ',' ENCLOSED BY '"' 
LINES TERMINATED BY '\n' IGNORE 1 LINES 
(Date,col2,col3,col4,col5,col6,col7,@dummy_variable)
Set dummy_variable = 0

加载正常,但日期格式显示为0000-00-00

csv中的日期采用[{1}}样式,无法在csv文件中更改。

1 个答案:

答案 0 :(得分:1)

您需要使用str_to_date

将日期调整为mysql格式

下面的内容应该有效。

LOAD DATA INFILE 'filename.csv' INTO TABLE table_name 
FIELDS TERMINATED BY ',' ENCLOSED BY '"' 
LINES TERMINATED BY '\n' IGNORE 1 LINES 
(@myDate,col2,col3,col4,col5,col6,col7,@dummy_variable)
Set dummy_variable = 0, Date = str_to_date(@myDate,'%d/%m/%Y')