天天看點

mysql Communications link failure 異常解決方案

主要異常資訊(注意:解決方案在最後)

The last packet successfully received from the server was 5,005 milliseconds ago. The last packet sent successfully to the server was 5,007 milliseconds ago.

日志截圖

mysql Communications link failure 異常解決方案

百度一下,一搜一大把資料,但是大緻大多有以下兩種方案

網上方案一:修改mysql以下配置,重新開機mysql

set wait_timeout=604800;

set interactive_timeout=604800;

網上方案二:jdbcUrl後面加上 autoReconnect 配置

autoReconnect=true

例如:jdbc:mysql://localhost:3306/db_name?autoReconnect=true

但是我試過以上兩種方案均無效,異常依然出現

主要原因

sql運作時間過長

最終解決方案

方案一:

優化sql,添加索引。

方案二:

jdbcUrl後面加上 connectTimeout 和 socketTimeout 配置,值可以根據異常資訊進行修改

connectTimeout=6000&socketTimeout=6000

​​​​​​​jdbc:mysql://localhost:3306/db_name?autoReconnect=true&connectTimeout=6000&socketTimeout=6000
           

繼續閱讀