IDEA连接mysql又报错!Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTime

Posted King-D

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了IDEA连接mysql又报错!Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTime相关的知识,希望对你有一定的参考价值。

错误界面

IDEA连接mysql,地址,用户名,密码,数据库名,全都配置好了,点测试连接,咔!不成功!

界面是这样的,

 

 

 

翻译过来就是:服务器返回无效时区。进入“高级”选项卡,手动设置“serverTimezone”属性。

看起来是时区出了问题。时区怎么会出问题?坑真多。网上搜了各种解决办法,琳琅满目,复杂的简单的,总算是解决了!

解决方案
我的问题出在两块,第一,设置mysql的时区。第二,mysql驱动的版本。详细步骤如下:

第一,设置mysql时区。
1,我们先来检查下mysql时区。

 

 

配置完环境变量,就可以在命令窗口直接执行下面的命令啦!

进入命令窗口(Win + R),连接数据库 mysql -hlocalhost -uroot -p,回车,输入密码,回车,如图:

 

 

 

2,继续输入 show variables like\'%time_zone\';    (注意不要漏掉后面的分号),回车,如图:

 

 

 

显示 SYSTEM 就是没有设置时区啦。

3,现在我们来设置时区。

输入set global time_zone = \'+8:00\';  注意不要漏掉后面的分号),回车,如图:

 

 

 

这便是设置成功啦!

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

第二,同步mysql驱动。

我本机安装的mysql版本是5.7的,那么IDEA要连接mysql也应该匹配下驱动版本。把Driver改成MySQL for 5.1就可以了

 

 

 在点击Test Connection测试下,成功啦!

 

 

【补充】

如果,你选的是MySQL,

数据库又是其他版本的,也没关系。

在驱动列表里找到 MySQL ,右边Driver files 里,选择一下你需要的版本,保存就可以了。

 

 

以上是关于IDEA连接mysql又报错!Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTime的主要内容,如果未能解决你的问题,请参考以下文章

IDEA配置IDEA连接mysql报错Server returns invalid timezone. Go to 'Advanced' tab and set 'serv

Idea连接MySQL异常[Could not create connection to database server. Attempted reconnect 3 times.]

Idea连接MySQL异常[Could not create connection to database server. Attempted reconnect 3 times.]

Idea连接MySQL异常[Could not create connection to database server. Attempted reconnect 3 times.]

IDEA 配置连接数据库报错 Server returns invalid timezone. Need to set ‘serverTimezone‘ property.

idea连接数据库报错 Server returns invalid timezone. Need to set‘serverTimezone’property