查看时区:
SHOW VARIABLES LIKE "%time_zone%";
输出
Variable_name Value
system_time_zone CST
time_zone SYSTEM
分析:
这里有两个变量,其中 time_zone 是指 mysql 数据库的时区。默认为 SYSTEM,即等于服务器的系统时区。
system_time_zone 表示系统时区,因为我们的系统服务器是在中国,system_time_zone 为 CST(China Standard Time)。
这里有个坑,CST 除了表示中国时区,它还有更多含义:
- 美国中部时间 Central Standard Time (USA) UTC-06:00
- 澳大利亚中部时间 Central Standard Time (Australia) UTC+09:30
- 中国标准时 China Standard Time UTC+08:00
- 古巴标准时 Cuba Standard Time UTC-04:00
比如说 jdk 驱动在读取到数据库时区为 CST后,它会默认理解为 美国中部时间,会将你当前时间改为 Timestamp -5:00。而实际上 mysql 的时区是 +8 时区,会将传过来的时间再 -8,即 Timestamp -13:00 转换为 这样就可能与你实际的时间少13个小时。
mysql 杂记 —— 时区问题
原文:https://www.cnblogs.com/lemos/p/11935682.html