t9540513

資料庫 Mysql 連接超時解法 「作者 : yasc5223」

發表於 2022-3-8 17:25:01
t9540513 發表於 2022-3-8 17:25:01 | 顯示全部樓層 |閱讀模式
001.png


【前言】
大家好,我是新人,今天來分享架服一開始沒人玩的話,
大概會遇到一個問題如以下的錯誤代碼:

  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 server was 61144 seconds ago,
  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 server was
  13. 61144 seconds 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天不用重開囉^^


【後記】
補充方法

mysql目錄下,複製my-default.ini,命名為my.ini
編輯my.ini,在[mysqld]下方新增兩行
interactive_timeout=31536000
wait_timeout=31536000
重啟mysql,完成。

確認方法:
開啟cmd,cd到mysql\bin
接著mysql\bin> mysql -u root -p
會叫你輸入密碼(Enter password)
接著mysql> show variables like '%timeout%';
確認數值是否為給定值31536000。



【作者】:yasc5223
【整理】:AICL集團



瀏覽 3420 回復 0

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

返回頂部