我的产品有一个表格如下,paytime是varchar,addtime是int:
desc test1;
+---------+------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+-------+
| paytime | varchar(30) | YES | | NULL | |
| addtime | int(10) unsigned | NO | | NULL | |
+---------+------------------+------+-----+---------+-------+
服务器A>选择版本();
+-----------------+
| version() |
+-----------------+
| 5.6.36-82.0-log |
+-----------------+
服务器B>选择版本();
+------------+
| version() |
+------------+
| 5.5.33-log |
+------------+
服务器A>从test1选择from_unixtime(paytime),from_unixtime(addtime);
+----------------------------+------------------------+
| from_unixtime(paytime) | from_unixtime(addtime) |
+----------------------------+------------------------+
| 2018-01-18 01:56:12.000000 | 2018-01-18 01:56:12 |
+----------------------------+------------------------+
服务器B>从test1选择from_unixtime(paytime),from_unixtime(addtime);
+------------------------+------------------------+
| from_unixtime(paytime) | from_unixtime(addtime) |
+------------------------+------------------------+
| 2018-01-18 01:56:12 | 2018-01-18 01:56:12 |
+------------------------+------------------------+
如你所见,当我使用from_unixtime时,mysql 5.5返回' 2018-01-18 01:56:12',mysql 5.6返回' 2018-01-18 01:56: 12'当争论是字符串类型。谁知道原因?
答案 0 :(得分:1)
此行为与bug reported有关。
要解决您的问题,直到错误得到解决,一种解决方法是在datetime
中明确指定from_unixtime
格式
SELECT from_unixtime('1516240572', '%Y-%m-%d %H:%i:%s');
Output:- 2018-01-18 01:56:12