8

How do you set the behavior of MySQL's automatic reconnection behavior in django?
I'm assuming this is a client side configuration, correct?

Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359

1 Answers1

1

Django database wrappers have a method called is_usable() that pings the server to check if it's up. This is the one for MySQL -

def is_usable(self):
    try:
        self.connection.ping()
    except DatabaseError:
        return False
    else:
        return True

From MySQL url you provided -

If auto-reconnect is enabled, mysql_ping() performs a reconnect. Otherwise, it returns an error.

So it all depends on how you configured this part -

mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);

which you have to set yourself on the DBMS.

Bibhas Debnath
  • 14,559
  • 17
  • 68
  • 96