SqlAlchemy: SQLError: (OperationalError) (2006, ‘MySQL server has gone away’)

March 2, 2008 § Leave a comment

What is this problem about:

This is actually MySQL error message. It means that there are no MySQL connections anymore.By MySQL default, idling database connections will be closed after 8 hours. Not having MySQL connections means that no SQL operations can be performed. SqlAlchemy is simple reporting the error.

When using SQLAlchemy, how to prevent such problems?

See sample code below:

engine = create_engine(db_path, pool_size = 100, pool_recycle=7200)

 Take a look at the pool_recycle variable. That will configure SqlAlchemy engine to reconnect every x number of seconds. This easy solution makes sure the existence of MySQL connection.

References:

Leave a comment

What’s this?

You are currently reading SqlAlchemy: SQLError: (OperationalError) (2006, ‘MySQL server has gone away’) at RAPD.

meta