2020-04-21 13:49:27.504 ERROR 8432 — [eate-1102607850] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://localhost:3305/demo?useUnicode=true&characterEncoding=utf-8, errorCode 0, state 01S00
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.
2020-04-21 13:49:50.494 ERROR 8432 — [eate-1102607850] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://localhost:3305/demo?useUnicode=true&characterEncoding=utf-8, errorCode 0, state 01S00
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) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:89) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:63) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:73) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.ConnectionImpl.(ConnectionImpl.java:456) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:197) ~[mysql-connector-java-8.0.19.jar:8.0.19]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1510) ~[druid-1.1.6.jar:1.1.6]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1575) ~[druid-1.1.6.jar:1.1.6]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2450) ~[druid-1.1.6.jar:1.1.6]
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.GeneratedConstructorAccessor54.newInstance(Unknown Source) ~[na:na]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_162]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_162]
mysql-connection-java版本导致时区的问题。
可能是因为版本原因。
1.pom.xml文件中去掉version5.1.47
或者改成8版本
mysql
mysql-connector-java
runtime
2.aplication.properties配置文件后加入 serverTimezone=UTC
spring.datasource.url=jdbc:mysql://localhost:3305/demo?useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
com.mysql.jdbc.Driver 是 mysql-connector-java 5中的
JDBC连接Mysql5 com.mysql.jdbc.Driver:com.mysql.cj.jdbc.Driver 是 mysql-connector-java 6中的
JDBC连接Mysql6 com.mysql.cj.jdbc.Driver, 需要指定时区serverTimezone:
1、JDBC连接Mysql5 com.mysql.jdbc.Driver:
driverClassName=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3305/demo?useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=123
2、JDBC连接Mysql6 com.mysql.cj.jdbc.Driver, 需要指定时区serverTimezone:
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3305/demo?serverTimezone=UTC&?useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=123
在设定时区的时候,如果设定serverTimezone=UTC,会比中国时间早8个小时,如果在中国,可以选择Asia/Shanghai或者Asia/Hongkong,例如:
driverClassName=com.mysql.cj.jdbc.Driver
url=jdbc:mysql://localhost:3305/demo?serverTimezone=Shanghai&?useUnicode=true&characterEncoding=utf8&useSSL=false
username=root
password=
官网文档地址:
https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-versions.html (Connector/J Versions 5.1)
https://dev.mysql.com/doc/connector-j/6.0/en/connector-j-versions.html (Connector/J Versions 6.0)