• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Benjamin

            靜以修身,儉以養(yǎng)德,非澹薄無以明志,非寧靜無以致遠。
            隨筆 - 397, 文章 - 0, 評論 - 196, 引用 - 0
            數(shù)據(jù)加載中……

            MySQLdb._exceptions.OperationalError: (2006, 'MySQL server has gone away')解決方法

            一、查詢mysql的show variables like “%timeout%”;interactive_timeout服務器關閉交互式連接前等待活動的秒數(shù) 參數(shù)默認值:28800秒(8小時)
            在配置文件my.cnf中只設置參數(shù)interactive_timeout=100或者設置一個比較大的值,則重啟服務器后進入或者set global interactive_timeout=28800;重啟mysql服務器
            注:
            從文檔上來看wait_timeout和interactive_timeout都是指不活躍的連接超時時間,連接線程啟動的時候wait_timeout會根據(jù)是交互模式還是非交互模式被設置為這兩個值中的一個。
            如果我們運行mysql -uroot -p命令登陸到mysql,wait_timeout就會被設置為interactive_timeout的值。如果我們在wait_timeout時間內(nèi)沒有進行任何操作,那么再次操作的時候就會提示超時,這是mysql client會重新連接。
            interactive_timeout和wait_timeout在連接空閑階段(sleep)起作用,對于保持sleep狀態(tài)超過了wait_timeout(或interactive_timeout,取決于CLIENT_INTERACTIVE標志)的客戶端,MySQL會主動斷開連接。
            可以用set命令或在my.cnf文件中設置,設置后需要重啟數(shù)據(jù)庫
            二、conn = None
            def _conn():  # 連接帶異常處理
                try:
                    global conn
                    conn = MySQLdb.connect(host="localhost", user="root", passwd="123456", db="xhaccount", port=3306,
                                           charset="utf8")  # 連接對象
                    return True
                except Exception as e:
                    print("str(Exception):\t", str(e))
                    print("str(e):\t\t", str(e))
                    print("repr(e):\t", repr(e))
                    # Get information about the exception that is currently being handled
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    print('e.message:\t', exc_value)
                    print("Note, object e and exc of Class %s is %s the same." %
                          (type(exc_value), ('not', '')[exc_value is e]))
                    print('traceback.print_exc(): ', traceback.print_exc())
                    return False
            def _reConn():  # 重試連接
                try:
                    conn.ping()  # 校驗連接是否異常
                except Exception as e:
                    if _conn() is True:  # 重新連接,成功退出
                        return
                    print("str(Exception):\t", str(e))
                    print("str(e):\t\t", str(e))
                    print("repr(e):\t", repr(e))
                    # Get information about the exception that is currently being handled
                    exc_type, exc_value, exc_traceback = sys.exc_info()
                    print('e.message:\t', exc_value)
                    print("Note, object e and exc of Class %s is %s the same." %
                          (type(exc_value), ('not', '')[exc_value is e]))
                    print('traceback.print_exc(): ', traceback.print_exc())
                    print('重連失敗!!!!!!!')
            每次執(zhí)行sql語句的時候,調(diào)用下_reConn()

            posted on 2020-12-30 09:44 Benjamin 閱讀(2413) 評論(0)  編輯 收藏 引用 所屬分類: python

            久久精品国产亚洲AV忘忧草18 | 亚洲国产成人久久笫一页| 国产精品九九久久免费视频 | 国产成人精品三上悠亚久久| 日韩人妻无码一区二区三区久久99| 麻豆av久久av盛宴av| 久久99精品久久久久久久不卡| 色综合久久综合网观看| 精品国产99久久久久久麻豆| 久久中文骚妇内射| 性做久久久久久免费观看| 五月丁香综合激情六月久久| 久久国产三级无码一区二区| 久久精品视频一| 久久久久久A亚洲欧洲AV冫| 久久久久AV综合网成人| 伊人久久大香线蕉综合5g| 2021国产成人精品久久| 久久久久亚洲av无码专区喷水| 久久国产成人| 国产精品熟女福利久久AV| 久久久久人妻精品一区二区三区 | 久久人人爽人人爽人人片av麻烦 | 久久亚洲国产成人影院网站| 久久精品无码专区免费青青| 2021国内久久精品| 亚洲国产精品无码久久九九| 亚洲国产精品久久66| 久久久久久a亚洲欧洲aⅴ | 色欲久久久天天天综合网精品| 久久www免费人成看国产片| 狠狠色婷婷综合天天久久丁香 | 久久天堂AV综合合色蜜桃网| 伊人久久大香线蕉AV一区二区| 久久久久国产精品麻豆AR影院| 99久久国产综合精品五月天喷水| jizzjizz国产精品久久| 日韩人妻无码一区二区三区久久| 亚洲色婷婷综合久久| 久久久久女人精品毛片| 国产成人精品白浆久久69 |