Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL's auto-reconnect in django

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

like image 365
Jonathan Livni Avatar asked Dec 04 '11 09:12

Jonathan Livni


1 Answers

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.

like image 187
Bibhas Debnath Avatar answered Sep 19 '22 10:09

Bibhas Debnath