• <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)德,非澹薄無以明志,非寧靜無以致遠(yuǎn)。
            隨筆 - 397, 文章 - 0, 評論 - 196, 引用 - 0
            數(shù)據(jù)加載中……

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

            一、查詢mysql的show variables like “%timeout%”;interactive_timeout服務(wù)器關(guān)閉交互式連接前等待活動(dòng)的秒數(shù) 參數(shù)默認(rèn)值:28800秒(8小時(shí))
            在配置文件my.cnf中只設(shè)置參數(shù)interactive_timeout=100或者設(shè)置一個(gè)比較大的值,則重啟服務(wù)器后進(jìn)入或者set global interactive_timeout=28800;重啟mysql服務(wù)器
            注:
            從文檔上來看wait_timeout和interactive_timeout都是指不活躍的連接超時(shí)時(shí)間,連接線程啟動(dòng)的時(shí)候wait_timeout會根據(jù)是交互模式還是非交互模式被設(shè)置為這兩個(gè)值中的一個(gè)。
            如果我們運(yùn)行mysql -uroot -p命令登陸到mysql,wait_timeout就會被設(shè)置為interactive_timeout的值。如果我們在wait_timeout時(shí)間內(nèi)沒有進(jìn)行任何操作,那么再次操作的時(shí)候就會提示超時(shí),這是mysql client會重新連接。
            interactive_timeout和wait_timeout在連接空閑階段(sleep)起作用,對于保持sleep狀態(tài)超過了wait_timeout(或interactive_timeout,取決于CLIENT_INTERACTIVE標(biāo)志)的客戶端,MySQL會主動(dòng)斷開連接。
            可以用set命令或在my.cnf文件中設(shè)置,設(shè)置后需要重啟數(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()  # 校驗(yàn)連接是否異常
                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語句的時(shí)候,調(diào)用下_reConn()

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

            久久精品国产WWW456C0M| 亚洲人成精品久久久久 | 性做久久久久久久久久久| 久久国产综合精品五月天| 久久噜噜久久久精品66| 欧美精品国产综合久久| 久久99精品国产一区二区三区| 久久精品国产一区二区| 久久午夜夜伦鲁鲁片免费无码影视| 精品久久久无码人妻中文字幕豆芽 | 亚洲AV日韩精品久久久久| 久久这里只有精品首页| 久久伊人精品一区二区三区| 国产69精品久久久久777| 亚洲国产一成久久精品国产成人综合 | 999久久久免费精品国产| 久久久久国色AV免费看图片| 久久久久久毛片免费播放| 久久精品不卡| 日韩精品久久久久久| 久久久亚洲AV波多野结衣| 久久天天躁狠狠躁夜夜2020老熟妇 | 久久精品国产亚洲AV不卡| 91精品国产91久久久久久| 久久精品国产亚洲AV大全| 亚洲色欲久久久综合网东京热| 久久免费香蕉视频| 精品久久久无码中文字幕| 国产亚洲欧美成人久久片| 精品久久无码中文字幕| 欧美精品久久久久久久自慰| 亚洲欧美伊人久久综合一区二区| 亚洲精品无码久久不卡| 伊人热热久久原色播放www | 国产精品欧美久久久久无广告| 久久精品国产精品国产精品污 | 久久人妻少妇嫩草AV无码专区| 久久精品综合网| 亚洲国产精品久久久天堂 | 日本久久久精品中文字幕| 97久久精品无码一区二区天美|