goterpsgo
goterpsgo

Reputation: 317

"MySQL server has gone away" error after long idle

I know this issue is not a new one on SO but I'm unable to find a solution. Whenever I return to my desk after leaving my app running overnight, I get a MySQL server has gone away error that persists until I restart my uwsgi service. I've already done the following:

but nothing has had any effect.

Upvotes: 0

Views: 525

Answers (1)

Jacob Ikedichi
Jacob Ikedichi

Reputation: 36

From the sqlalchemy doc located here, the pool_recycle feature is what you are looking for.

from sqlalchemy import create_engine

engine = create_engine("mysql://scott:tiger@localhost/test", pool_recycle=28700)

Set pool_recycle to a value < wait_timeout in your mysql configuration file my.cnf

MySQL default wait_time is 28800 (8 hrs)

Dont forget to restart your services (i.e. mysql, etc) if you do modify the conf files

Upvotes: 1

Related Questions