IDEA连接mysql失败!!报Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ prope

今天创建了springboot项目,然后连接数据库的时候显示(Server returns invalid timezone. Go to 'Advanced' tab and set 'serverTimezone' prope),以下是解决办法,亲测有效。

错误界面

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

界面是这样的,

IDEA连接mysql失败!!报Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ prope

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

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

解决方案

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

第一,设置mysql时区。

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

(  这里有个小插曲~~~~~~~你的mysql,配置好环境变量了吗 )

IDEA连接mysql失败!!报Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ prope

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

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

IDEA连接mysql失败!!报Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ prope

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

IDEA连接mysql失败!!报Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ prope

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

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

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

IDEA连接mysql失败!!报Server returns invalid timezone. Go to ‘Advanced‘ tab and set ‘serverTimezone‘ prope

这便是设置成功啦!