"ping" not reconnecting in Python MySQLdb client interface

John Nagle nagle at animats.com
Sun Feb 3 09:36:56 CET 2008

    I have some long-running Python programs that can be idle
for hours, and, of course, the MySQL connection times out.
So I call


at the beginning of a new request cycle.  This should
reestablish the connection, but it doesn't:

   Traceback (most recent call last):
   File "rateapiv1.fcgi", line 60, in QuickSitetruthQuery
   db.ping() # reattach connection if necessary
   OperationalError: (2006, 'MySQL server has gone away')

The MySQL server is up, and new connection attempts succeed.

This problem was reported two years ago relative to TurboGears:


I suspect that MySQL has auto-reconnect turned off, but doesn't document this.

(MySQL 5 on Fedora Core)

				John Nagle

More information about the Python-list mailing list