<p>I came across PHP way of doing the trick:</p>

<pre><code>my_bool reconnect = 1;
mysql_options(&amp;mysql, MYSQL_OPT_RECONNECT, &amp;reconnect);
</code></pre>

<p>but no luck with MySQLdb (python-mysql).</p>

<p>Can anybody please give a clue? Thanks.</p>

If you are using ubuntu Linux there was a patch added to the python-mysql package that added the ability to set that same MYSQL_OPT_RECONNECT option (see
here
).  I have not tried it though.
Unfortunately, the patch was later removed due to a conflict with autoconnect and transations (described
here
).
The comments from that page say:
1.2.2-7 Published in intrepid-release on 2008-06-19
python-mysqldb (1.2.2-7) unstable; urgency=low
[ Sandro Tosi ]
  * debian/control
    - list items lines in description starts with 2 space, to avoid reformat
      on webpages (Closes: #480341)
[ Bernd Zeimetz ]
  * debian/patches/02_reconnect.dpatch:
    - Dropping patch:
      Comment in Storm which explains the problem:
```
```
# Here is another sad story about bad transactional behavior. MySQL
    # offers a feature to automatically reconnect dropped connections.
    # What sounds like a dream, is actually a nightmare for anyone who
    # is dealing with transactions. When a reconnection happens, the
    # currently running transaction is transparently rolled back, and
    # everything that was being done is lost, without notice. Not only
    # that, but the connection may be put back in AUTOCOMMIT mode, even
    # when that's not the default MySQLdb behavior. The MySQL developers
    # quickly understood that this is a terrible idea, and removed the
    # behavior in MySQL 5.0.3. Unfortunately, Debian and Ubuntu still
    # have a patch right now which *reenables* that behavior by default
    # even past version 5.0.3.
```
```