springboot集成mybatis,连接mysql时报CannotGetJdbcConnectionException


 如下图所示异常:

1 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.
2 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_102] 3 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_102] 4 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_102] 5 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_102]

分析过程:

首先:有一条红色警告。

Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.

 

按照提示将 spring.datasource.driverClassName 修改为 com.mysql.cj.jdbc.Driver

spring.datasource.driverClassName=com.mysql.jdbc.Driver

 

其次,我的 mysql-connector-java 版本为 8.0.18,在url上需要添加时区信息:

jdbc:mysql://host:port/dbname?characterEncoding=utf8&serverTimezone=UTC

添加后,异常消失。

 

 

 

PS:从6.0.2版本开始,如果mysql server未明确配置时区,则必须在jdbc连接参数中设置serverTimezone
否则,在启动时报错


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM