zoukankan      html  css  js  c++  java
  • 【异常】The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

    异常错误: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.

     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 'Öйú±ê׼ʱ¼ä' 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 'Öйú±ê׼ʱ¼ä' 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
    作者:容一博

    个性签名:我有一个不成熟的想法!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

  • 相关阅读:
    git 基本使用
    docker下rabbitMQ高可用集群部署
    成长路上破局思维:工具化时间管理
    图解Elasticsearch的核心概念
    先森林后树木:Elasticsearch各版本升级核心内容必看
    JRebel 破解最简单的使用
    POA理论:不要被你的目标欺骗了你
    读了《跃迁-成为高手的技术》我的工资翻倍了
    微信头像地址失效踩坑记附带方案
    如何做程序员喜欢的测试妹子?
  • 原文地址:https://www.cnblogs.com/chromer/p/2fd23rgv52fc.html
Copyright © 2011-2022 走看看