IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper

错误界面
IDEA连接mysql,地址,用户名,密码,数据库名,全都配置好了,点测试连接,界面是这样的,
IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper
翻译过来就是:服务器返回无效时区。进入“高级”选项卡,手动设置“serverTimezone”属性。

看起来是时区出了问题。时区怎么会出问题?

解决方案

第一,设置mysql的时区。第二,mysql驱动的版本。详细步骤如下:

第一,设置mysql时区。

  1. 我们先来检查下mysql时区。

配置好 mysql 环境变量
IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper
进入命令窗口(Win + R),连接数据库 mysql -hlocalhost -uroot -p,回车,输入密码,回车,如图:
IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper

  1. 继续输入 show variables like'%time_zone'; (注意不要漏掉后面的分号),回车,如图:
    IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper
    显示 SYSTEM 就是没有设置时区啦。

  2. 现在我们来设置时区。输入set global time_zone = '+8:00'; 注意不要漏掉后面的分号),回车,如图:
    IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper
    设置成功

这时你重新连接下数据库,也许能连接成功!如果没有,就继续!

第二,同步mysql驱动。

我安装的mysql版本是8.0,那么IDEA要连接mysql也应该匹配下驱动版本。把Driver改成MySQL for 8.0就可以了。
IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper
在点击Test Connection测试下,成功啦!
IDEA连接Mysql 提示 Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' proper