微信扫一扫 分享朋友圈

已有 1191 人浏览分享

[服務器教學] 資料庫 Mysql 連接超時解法 「作者 : yasc5223」

[複製鏈接]

區域版主

Rank: 10Rank: 10Rank: 10

245

威望

1142

金錢

592

A幣
主題
130
帖子
245
精華
0
綜合社群主題發文量
9
電玩社群主題發文量
10
娛樂社群主題發文量
0
技術社群主題發文量
89
閱讀權限
100
註冊時間
2016-5-17
  • TA的每日心情

    2022-4-29 14:36
  • 簽到天數: 5 天

    連續簽到: 1 天

    [LV.2]偶爾看看I

    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集團



    共收到 0 A幣
    打賞榜
    暫無
    暫無
    暫無
    暫無
    ----
    暫無
    ----
    暫無
    ----
    暫無
    ----
    您需要登錄後才可以回帖 登錄 | 註冊會員

    本版積分規則

    245

    發文

    1142

    金錢

    592

    A幣

    ----------榮譽勳章----------

    熱門推薦
    圖文推薦
    • 聯繫我們

    小黑屋|AICL社群娛樂集團

    GMT+8, 2024-4-26 13:13 , 網路刷新 0.105873 秒 .

    歡迎來到 AICL網路社群

    版權AICL社群所有 2011-2021.

    Total:123 Today:213 Online:322