IDEA使用java操作Mysql数据库错误提示time zone

IDEA使用java操作Mysql数据库错误提示time zone

一、使用场景

IDEA开发工具使用java操作数据库时候,运行代码提示rime zone错误。如下是错误提示:

is unrecognized or represents more than one time zone.
 You must configure either the server or JDBC driver 
(via the serverTimezone configuration property) to use 
a more specifc time zone value if you want to utilize 
time zone support.

二、错误原因

1、使用了高版本的mysql驱动。mysql:mysql-connector-java:8.0.11

2、从错误上看应该是时区的错误,所以我们只需要设置完毕系统的时区。

三、解决方案

方案一、

在连接url中加入参数 serverTimezone=GMT%2B8,GMT%2B8代表东八区

jdbc:mysql://localhost:3306/testuseUnicode=true&character
Encoding=utf8&autoReconnect=true&serverTimezone=GMT%2B8  

方案二、

设置整个数据库的时区。

在数据库中执行如下sql语句

show variables like '%time_zone%'  
set global time_zone='+8:00';  

 

你可能感兴趣的:(开发工具,#,开发工具【IDEA】)