The server time zone value '&#214…

2018-09-29 04:02:20来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

异常错误:The server time zone value '?D1ú±ê×?ê±??' 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 Thu Sep 27 00:18:47 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
 2 java.sql.SQLException: The server time zone value '?D1ú±ê×?ê±??' 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.
 3     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
 4     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
 5     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)
 6     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)
 7     at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)
 8     at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)
 9     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:832)
10     at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
11     at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)
12     at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:207)
13     at java.sql.DriverManager.getConnection(DriverManager.java:664)
14     at java.sql.DriverManager.getConnection(DriverManager.java:247)
15     at com.jdbc.chap02.sec03.Demo1.main(Demo1.java:33)
16 Caused by: com.mysql.cj.exceptions.InvalidConnectionAttributeException: The server time zone value '?D1ú±ê×?ê±??' 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.
17     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
18     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
19     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
20     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
21     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)
22     at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)
23     at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:128)
24     at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2236)
25     at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2260)
26     at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1314)
27     at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:963)
28     at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:822)
29     ... 6 more
View Code

我用了8.0版本的MySQL连接驱动。现在按照最新官方提示支持将com.mysql.jdbc.Driver  改为  com.mysql.cj.jdbc.Driver

1 //驱动名称
2 private static String jdbcName = "com.mysql.cj.jdbc.Driver";
3 //数据库地址
4 private static String dbUrl = "jdbc:mysql://localhost:3306/db_book";
5 //数据库用户名
6 private static String dbUser = "root";
7 //数据库密码
8 private static String dbPassword = "123456";

我们还需要在访问数据库的Url后面加上以下的语句即可:

1 private static String dbUrl = "jdbc:mysql://localhost:3306/db_book?serverTimezone=GMT%2B8"

从错误上看应该是时区的错误,所以我们只需要设置完毕系统的时区即可。这里的GMT%2B8代表东八区。

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

1 show variables like '%time_zone%'
2 set global time_zone='+8:00';
3 #执行结果:
4    Variable_name          Value
5 system_time_zone    
6       time_zone             SYSTEM

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:CentOS7.x+JDK+Mysql+Tomcat服务器环境web项目部署

下一篇:spring 读取properties文件--通过注解方式