目錄
具體出錯(cuò)信息
網(wǎng)上的一些方案
解決方案
具體出錯(cuò)信息
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.
?
網(wǎng)上的一些方案
調(diào)大 mysql 的 wait_timeout
使用autoReconnect=true&failOverReadOnly=false,(只對(duì)mysql 4之前的版本有效)
以上解決方案的報(bào)錯(cuò)信息中的時(shí)間一般都很大比如
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.
但是我的這個(gè)錯(cuò)誤并不是超時(shí),因?yàn)閣ait_timeout 默認(rèn)是 8小時(shí),而報(bào)錯(cuò)信息中的時(shí)間只有233ms。
解決方案
這種情況下 可以嘗試將
配置文件中的Driver設(shè)置為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依賴可以設(shè)置為6+版本文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-736278.html
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.28</version> </dependency>
改完后項(xiàng)目即可正常運(yùn)行。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-736278.html
到了這里,關(guān)于com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 解決方案的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!