java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä'...解决

在使用idea连接mysql测试时,报的错:

Cause: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' 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.

这是在使用MySQL8.0以上的版本的时候出现的错误,我们需要在访问数据库的URL后面追加一下参数即可:

?serverTimezone=GMT%2B8

 比如:我pom.xml文件中的依赖为:

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>8.0.15</version>
    </dependency>

我的URL为:

jdbc:mysql://localhost:3306/xjs

应该修改为:

jdbc:mysql://localhost:3306/xjs?serverTimezone=GMT%2B8

从错误上看应该是时区的错误,这里的GMT%2B8代表东八区。

还有一种解决方法就是设置整个数据库的时区,可以执行下面的语句来完成:

1.show variables like '%time_zone%'

2.set global time_zone='+8:00'

posted @ 2020-09-09 17:57  微微亮  阅读(341)  评论(0编辑  收藏  举报