MySQL連接超時(shí)自動(dòng)斷開連接問題
描述:
用mybatis2.3.5實(shí)現(xiàn)做應(yīng)用時(shí),程序中報(bào)以下錯(cuò)誤:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was 79,221,885 milliseconds ago.
The last packet sent successfully to the server was 79,221,885 milliseconds ago.
is longer than the server configured value of 'wait_timeout'.
You should consider either expiring and/or testing connection validity before use in your application,
increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
解釋及解決辦法:
如果連接閑置8小時(shí) (mysql的wait_timeout參數(shù)默認(rèn)時(shí)間), mysql就會自動(dòng)斷開連接, 得刷新應(yīng)用才行.
不用hibernate的話, connection url加參數(shù):
autoReconnect=true
用hibernate的話, 加如下屬性:
true true true
要是還用c3p0連接池:
1 0 0 true
例:
jdbc.url=jdbc:mysql://localhost:3306/yht_wxt?zeroDateTimeBehavior=convertToNull&useUnicode=True&characterEncoding=utf8&autoReconnect=true&autoReconnectForPools=true
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com