IntelliJ IDEA 连接到MySQL出现
Server returns invalid timezone. Need to set 'serverTimezone' property.
Set time zone
解决方法:
原博客地址:
https://www.cnblogs.com/fengxiaoqi/p/12897982.html
原因
时区问题,MySQL驱动默认UTC时区。
Mysql8.0+才会出现这类问题
--针对application 可以设置:
jdbc.url=jdbc:mysql://localhost:3306/ssmbuild?useSSL=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
(注意serverTimezone的写法serverTimeZone是不行的)
或者:
jdbc:mysql://localhost:3306/database?useUnicode=true&characterEncoding=UTF-8&useOldAliasMetadataBehavior=true&autoReconnect=true&serverTimeZone=UTC
解决方案
- 修改时区
# 设置全局时区 mysql> set global time_zone = '+8:00';
Query OK, 0 rows affected (0.00 sec)
# 设置时区为东八区 mysql> set time_zone = '+8:00';
Query OK, 0 rows affected (0.00 sec)
# 刷新权限使设置立即生效 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like '%time_zone%';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| system_time_zone | EST | | time_zone | +08:00 |
+------------------+--------+
2 rows in set (0.00 sec)
- 在url后添加:?serverTimezone=GMT%2B8