自動的に接続を切断するためのMySQLdb非アクティブソリューション

問題:

「:(2006、 『MySQLサーバが立ち去りました』)_mysql_exceptions.OperationalErrorは」非アクティブを延長した場合のMySQLdbのmysqlを経由して、mysqlの、再度要求例外をスローにつながる切断されます

理由:

MySQLは、接続が今回は、MySQL自動的に切断されます以上のMySQLdb後に自動的に非アクティブな接続を切断するには、2つのパラメータを持っているためです。

interactive_timeout
WAIT_TIMEOUT

あなたは、mysqlは「%タイムアウト%」ビューのようなショーのグローバル変数を実行訪問することができます

ソリューション:

道:

MySQLの構成変更は、上記の二つのパラメータを変更します

オプション2:

再接続するCONNピング()メソッドを使用して

CONN = MySQLdb.conn(XXXXX)
conn.ping(真)

ping(...)
    Checks whether or not the connection to the server is
    working. If it has gone down, an automatic reconnection is
    attempted.

    This function can be used by clients that remain idle for a
    long while, to check whether or not the server has closed the
    connection and reconnect if necessary.

    New in 1.2.2: Accepts an optional reconnect parameter. If True,
    then the client will attempt reconnection. Note that this setting
    is persistent. By default, this is on in MySQL<5.0.3, and off
    thereafter.

    Non-standard. You should assume that ping() performs an
    implicit rollback; use only when starting a new transaction.
    You have been warned.

おすすめ

転載: blog.51cto.com/4988084/2446062