[Twisted-Python] 2006, 'MySQL server has gone away'

Werner Thie wthie at thiengineering.ch
Thu Sep 20 07:39:58 EDT 2007

Hi all

While using mySQL V 5.0.33 and MySQL-python-1.2.2 with twisted/adbapi 
with the following connection params

     'host': 'xxx.xxx.xxx.xxx',
     'db': 'db',
     'user': 'dbuser',
     'passwd': 'dbpasswd'

I noticed (2006, 'MySQL server has gone away') errors, which seem to be 
not recoverable from an adbapi standpoint.

Further analysis and reading the mySQL manual showed, that the mySQL 
server in versions > 5 seems to close open connections after (default) 8 
hours. The reconnect feature of the db is disabled by default and there 
is no parameter to preset it via MySQL-python.

Further digging brought up this link


which patches the (also 1.2.2) version such, that a reconnect keyword is 
introduced in the DB_ARGS.

- are there any adverse effects in applying this patch and setting 
reconnect: 1 in DB_ARGS?

- is there a better, safer way to avoid this nasty error?

Thxs, Werner

More information about the Twisted-Python mailing list