MySQL CURTIME() 始终为 00:00:00

MySQL CURTIME() 始终为 00:00:00

我在 Solaris 10u8 上安装了 MySQL 服务器。直到最近,一切都运行良好。然后突然之间,MySQL 的当前时间总是 00:00:00。CURDATE() 似乎运行正常,只是它给出的时间仍然是 00:00:00。下面是我的问题的一些说明。我试过重启机器。我不知道该怎么做,这弄乱了我的 Web 应用程序。有什么想法吗?

-bash-4.1$ Fri Jul  9 11:01:42 EDT 2010
.......
.......
mysql> create table timetest (datetime datetime);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into timetest values (curtime());
Query OK, 1 row affected, 1 warning (0.01 sec)

mysql> select * from timetest;
+---------------------+
| datetime            |
+---------------------+
| 0000-00-00 00:00:00 |
+---------------------+
1 row in set (0.00 sec)

mysql> insert into timetest values (curdate());
Query OK, 1 row affected (0.00 sec)

mysql> select * from timetest;
+---------------------+
| datetime            |
+---------------------+
| 0000-00-00 00:00:00 |
| 2010-07-09 00:00:00 |
+---------------------+
2 rows in set (0.00 sec)

答案1

您收到的警告如下:

+---------+------+-----------------------------------------------+
| Level   | Code | Message                                       |
+---------+------+-----------------------------------------------+
| Warning | 1265 | Data truncated for column 'datetime' at row 1 |
+---------+------+-----------------------------------------------+

show warnings;当发现警告时,您可以在执行另一个查询之前运行 when 来查看它。

该架构不支持您尝试插入的数据的时间。例如:

mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 11:18:19  |
+-----------+
1 row in set (0.00 sec)

curdate()仅产生日期:

mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2010-07-09 |
+------------+
1 row in set (0.00 sec)

now()以您想要的格式生成数据:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2010-07-09 11:20:31 |
+---------------------+
1 row in set (0.00 sec)

看:

mysql> insert into timetest values(now());
Query OK, 1 row affected (0.00 sec)

mysql> select * from timetest;
+---------------------+
| datetime            |
+---------------------+
| 0000-00-00 00:00:00 |
| 2010-07-09 11:20:56 |
+---------------------+
2 rows in set (0.00 sec)

答案2

您应该尝试 now()。

相关内容