Menu

#32 Interface to set MYSQL_OPT_RECONNECT

MySQLdb
open
MySQLdb (53)
5
2012-09-19
2006-05-06
No

My hosting provider reboots their mysql database every
hour, causing my persistent mysqldb apps to crash with
"mysql server has gone away".

This patch exposes the MYSQL_OPT_RECONNECT flag in the
connect() method. You can now send a keyword argument
of "reconnect=1" to cause the mysql API to attempt to
reconnect if the connection is lost.

Discussion

  • Paul Eastham

    Paul Eastham - 2006-05-13

    here's the patch

     
  • Sridhar Ratnakumar

    Logged In: YES
    user_id=1530153

    Is not this patch applied yet to the latest release?

     
  • sophana

    sophana - 2006-12-27

    Logged In: YES
    user_id=931678
    Originator: NO

    This patch is not in the 1.2.2 and it should!
    It does apply correctly on 1.2.2

     
  • Charles V.

    Charles V. - 2007-05-14

    Logged In: YES
    user_id=1772693
    Originator: NO

    Is there a reason to not apply this patch ?

     
  • Wladimir van der Laan

    Logged In: YES
    user_id=49336
    Originator: NO

    why is this still not in the latest release, it's very useful to include

     
  • phatmonkey

    phatmonkey - 2007-07-24

    Logged In: YES
    user_id=1005618
    Originator: NO

    Please include! It is indeed very useful

     
  • runz

    runz - 2007-10-04

    Logged In: YES
    user_id=1903663
    Originator: NO

    there is a bug in this patch. see the lines where the reconnect option told to the server (somewhere at line 570):

    if (reconnect > 0) {
    my_bool bool = reconnect;
    mysql_options(conn, MYSQL_OPT_RECONNECT, &bool);
    }

    this if statement has to be tested against the connection (conn) like this:

    if ((reconnect > 0) && (conn)) {
    my_bool bool = reconnect;
    mysql_options(conn, MYSQL_OPT_RECONNECT, &bool);
    }

    Otherwise false parameters to connection will cause a segmentation fault at this point, because the connection doesn't exist at all.

     
  • Bernd Zeimetz

    Bernd Zeimetz - 2007-10-06

    Logged In: YES
    user_id=721761
    Originator: NO

    The developers of Zenoss modified the patch a little bit:

    • if (conn && reconnect > 0) {
    • my_bool bool = reconnect;
    • mysql_options(conn, MYSQL_OPT_RECONNECT, &bool);
    • }

    find the updated patch here:
    http://dev.zenoss.com/svn/trunk/inst/externallibs/MySQL-python-1.2.0.patch02

    Please apply to the next version,

    thanks

    Bernd

     
  • darking

    darking - 2008-10-23

    Isn't there already the option "reconnect" in the latest version?

    Close?

     
  • Andy Dustman

    Andy Dustman - 2008-10-23

    There is, as an optional argument to connection.ping().

    This is an extremely dangerous option that I'm not going to support. It's disabled in MySQL-5.0 and up for a reason: It silently reconnects to the database which rolls back any transaction you might have in progress.

    I suppose I could make it a conditional compilation option, but if you use transactions, you should never use this. Write your application to recover from errors instead.

     
  • Andy Dustman

    Andy Dustman - 2008-10-23

    Your patch will not be applied.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.