目录
具体出错信息
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 233 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
网上的一些方案
调大 mysql 的 wait_timeout
使用autoReconnect=true&failOverReadOnly=false,(只对mysql 4之前的版本有效)
以上解决方案的报错信息中的时间一般都很大比如
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 1,548,635,756,564 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
但是我的这个错误并不是超时,因为wait_timeout 默认是 8小时,而报错信息中的时间只有233ms。
解决方案
这种情况下 可以尝试将
配置文件中的Driver设置为com.mysql.cj.jdbc.Driver
com.mysql.jdbc.Driver 是mybatis-connection-java 5 及 5 以下的
com.mysql.cj.jdbc.Driver是mybatis-connection-Java 6 及以上的
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver
pom中mysql依赖可以设置为6+版本
mysql mysql-connector-java 8.0.28
改完后项目即可正常运行。
来源地址:https://blog.csdn.net/weixin_40757930/article/details/128997068