yasc5223

Mysql連接超時

發表於 2018-8-24 11:06:35
yasc5223 發表於 2018-8-24 11:06:35 | 顯示全部樓層 |閱讀模式
大家好,我是新人,今天來分享架服一開始沒人玩的話,大概會遇到一個問題如以下的錯誤代碼
  1. [Saving] Error saving character data: com.mysql.jdbc.exceptions.jdbc4.Communicat
  2. ionsException: The last packet successfully received from the server was61144 se
  3. conds ago.The last packet sent successfully to the [color=Red]server was 61144 seconds ago[/color],
  4. which  is longer than the server configured value of 'wait_timeout'. You should
  5. consider either expiring and/or testing connection validity before use in your
  6. application, increasing the server configured values for client timeouts, or usi
  7. ng the Connector/J connection property 'autoReconnect=true' to avoid this proble
  8. m.
  9. [Saving] Error rolling back: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientCo
  10. nnectionException: Can't call rollback when autocommit=true
  11. [Saving] Error going back to autocommit mode: com.mysql.jdbc.exceptions.jdbc4.Co
  12. mmunicationsException: The last packet successfully received from the [color=Red]server was
  13. 61144 seconds[/color] ago.The last packet sent successfully to the server was 61144 seco
  14. nds ago, which  is longer than the server configured value of 'wait_timeout'. Yo
  15. u should consider either expiring and/or testing connection validity before use
  16. in your application, increasing the server configured values for client timeouts
  17. , or using the Connector/J connection property 'autoReconnect=true' to avoid thi
  18. s problem.
複製代碼
目前測試是太久沒有登入遊戲,遊戲也沒人在玩的時候,會遇到這個問題,以下提供有效的暫時解決方法

點一下WAMP->MySQL->MySQL控制台
先輸入你的MySQL密碼(沒有設置密碼直接按Enter進入即可)
輸入 show variables like '%timeout%';
會看到有兩個數值為28800的參數,分別是 interactive_timeout和wait_timeout
28800是秒數,大家可以換算一下28800/60/60=8小時
意味著8小時若是沒有人對資料庫進行操作就會自動關閉,一般可重啟伺服器就可以解決了
但不想重啟伺服器的人可以使用以下方法
MySQL控制台輸入密碼後再輸入下面指令
set wait_timeout=2147483;
set interactive_timeout=2147483;
在這之後你再輸入 show variables like '%timeout%';檢查一下
就會發現你的 interactive_timeout和wait_timeout 這兩個值被改為2147483(大約是24天,目前測試為最大值)
這樣你的伺服器就可以24天不用重開囉^^

若有任何問題歡迎留言指教
瀏覽 5466 回復 1

您需要登錄後才可以回帖 登錄 | 註冊會員

返回頂部