现象:通过 IDEA 自带数据库工具连接 MySQL 失败;报错信息如下:
The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone
解决方法:
1、连接 MySQL 的 URL 添加时区:?serverTimezone=GMT%2B8
把
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false
改为:
url: jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&useSSL=false
2、设置MySQL时区为当前系统时区
8.0.13版本的MySQL,my.ini文件是在C:\ProgramData\MySQL\MySQL Server 8.0\my.ini目录下(安装C盘,ProgramData文件夹是隐藏的,推荐用everything直接搜索)。
打开my.ini文件,找到[mysqld]节点,在节点下加入:default-time-zone='+08:00'
3、修改MySQL配置文件my.ini
重启数据库服务,通过命令 show variables like '%time_zone%' 可验证是否生效
4、IDEA 自带 database 插件 Advanced 选项配置 serverTimezone 值为 GMT+8 即可
参考:https://www.jianshu.com/p/0d53218da27d