无法使用LOAD DATA将时间戳加载到MySQL表中

时间:2016-06-03 18:19:23

标签: mysql timestamp load

输入数据如下所示:

Incident ID,CR Number,Dispatch Date / Time
201073514,16016688,04/05/2016 10:07:48 PM
201073496,16016678,04/05/2016 08:53:35 PM
...
201073481,16016656,04/05/2016 06:47:01 PM

运行加载后

LOAD DATA  INFILE 'C:\\Temp\\orders.csv' INTO TABLE orders
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';

我尝试了不同的Dispatch_Date_Time类型,例如DATE / DATETIME / TIMESTAMP,但它总是为零:

mysql> select Dispatch_Date_Time from orders limit 5;
+---------------------+
| Dispatch_Date_Time  |
+---------------------+
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
| 0000-00-00 00:00:00 |
+---------------------+
5 rows in set (0.00 sec)

我做错了什么?

1 个答案:

答案 0 :(得分:0)

你可以像这样使用它:

LOAD DATA  INFILE 'C:\\Temp\\orders.csv'
INTO TABLE orders
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(c1, c2, @c3)
SET c3 = STR_TO_DATE(@c3,'%d/%m/%Y %I:%i:%s %p');