Python MySQLdb auto reconnect MYSQL_OPT_RECONNECT

19 Feb 2010

Auto-reconnect (MYSQL_OPT_RECONNECT) is available in the python MySQLdb client. Just add "reconnect=1" when you are creating a connection via MySQLdb.connect. At least it is on Ubuntu 9.10. Not documented.

The easy ways to test is to start your server, make a request to see you do have a connection, then restart mysql, the make a new request.

Note that auto-reconnect totally borks transactions, so this is best used for MyISAM tables and read-only queries elsewhere.

Comment 2010-03-07 by None

This doesn't seem to work for me on karmic 9.10. I will upgrade everything to be sure.

The patch seems to have been dropped again in Ubuntu Lucid: