Top

MySQL 8,java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.

MySQL MySQL  浏览 评论

MySQL8,在SpringBoot,Druid系统启动中,报如下异常错误;

原因是安装mysql的时候时区设置的不正确 mysql默认的是美国的时区,而我们中国大陆要比他们迟8小时,采用+8:00格式;

而且使用了MySQL8的高版本mysql jdbc驱动,如果是mysql5.7就不存在时区问题;


解决方法:

1、在jdbc连接url后加入serverTimezone=GMT参数:

jdbc:mysql://127.0.0.1:3306/temp?characterEncoding=UTF-8&useUnicode=true&useSSL=false&serverTimezone=GMT


2、修改MySQL配置文件,加入默认时区参数,在my.ini文件中[mysqld]节点下,加入default-time-zone='+08:00'参数:

  1. image.png


3、MySQL驱动Jar包:

mysql-connector-java-5.0.3-bin.jar 

mysql-connector-java-5.1.47-bin.jar 

mysql-connector-java-5.1.6-bin.jar 

mysql-connector-java-8.0.15.jar 


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.

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63)

at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73)

at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:835)

at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:455)

at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:240)

at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156)

at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:786)

at com.alibaba.druid.filter.FilterEventAdapter.connection_connect(FilterEventAdapter.java:38)

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)

at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:786)

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)

at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218)

at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150)

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1560)

at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623)

at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2468)

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.

at sun.reflect.GeneratedConstructorAccessor73.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

at java.lang.reflect.Constructor.newInstance(Constructor.java:423)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:61)

at com.mysql.cj.exceptions.ExceptionFactory.createException(ExceptionFactory.java:85)

at com.mysql.cj.util.TimeUtil.getCanonicalTimezone(TimeUtil.java:132)

at com.mysql.cj.protocol.a.NativeProtocol.configureTimezone(NativeProtocol.java:2241)

at com.mysql.cj.protocol.a.NativeProtocol.initServerSession(NativeProtocol.java:2265)

at com.mysql.cj.jdbc.ConnectionImpl.initializePropsFromServer(ConnectionImpl.java:1319)

at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:966)

at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:825)

... 14 common frames omitted