1 问题
java应用程序写入MySQL的数据时间字段小8小时
2 查看MySQL服务器时区配置
sql
mysql> show variables like '%time_zone';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | CST |
| time_zone | SYSTEM |
+------------------+--------+
mysql> select now(), curtime();
+---------------------+-----------+
| now() | curtime() |
+---------------------+-----------+
| 2024-10-17 16:32:33 | 16:32:33 |
+---------------------+-----------+
1 row in set (0.00 sec)
3 修改java应用连接mysql的url
添加serverTimezone=Asia/Shanghai,比如jdbc连接如下:
bash
jdbc:mysql://localhost:3306/db_name?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=Asia/Shanghai