查看时区:
mysql> show variables like ‘%time_zone%‘; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | SYSTEM | +------------------+--------+ 2 rows in set (0.02 sec)
查看当前时间也正常:
mysql> select now(); +---------------------+ | now() | +---------------------+ | 2016-12-27 22:29:59 | +---------------------+ 1 row in set (0.00 sec)
但是java写入是就少14小时。这是因为:在解析成预编译语句的时候,误将CST(China Standard Time utc+8)解析成CST(Central Standard Tim UTC-6),美国中部标准时间,所以少14个小时。
解决办法:
mysql> set GLOBAL time_zone = ‘+8:00‘; Query OK, 0 rows affected (0.00 sec) mysql> show variables like ‘%time_zone%‘; +------------------+--------+ | Variable_name | Value | +------------------+--------+ | system_time_zone | CST | | time_zone | +08:00 | +------------------+--------+ 2 rows in set (0.04 sec)
时间: 2024-12-14 10:56:55