I'm using Pylons (a python framework) to serve a simple web application, but it seems to die from time to time, with this in the error log: (2006, 'MySQL server has gone away')
I did a bit of checking, and saw that this was because the connections to MySQL were not being renewed. This shouldn't be a problem though, because the sqlalchemy.pool_recycle
in the config file should automatically keep it alive. The default was 3600
, but I dialed it back to 1800
because of this problem. It helped a bit, but 3600
should be fine according to the docs. The errors still happen semi-regularly. I don't want to lower it too much though and DOS my own database :).
Maybe something in my MySQL config is goofy? Not sure where to look exactly.
Other relevant details:
Python 2.5
Pylons: 0.9.6.2 (w/ sql_alchemy)
MySQL: 5.0.51
To fix, you can increase the maximal packet size limit max_allowed_packet in my. cnf file, eg. set max_allowed_packet = 128M , then restart your MySQL server: sudo /etc/init. d/mysql restart.
August 10, 2021 by Hayden James, in Blog Linux. The MySQL server has gone away error, means that MySQL server (mysqld) timed out and closed the connection. By default, MySQL will close connections after eight hours (28800 seconds) if nothing happens.
A Connection Timed Out error occurs when the database's firewall won't allow you to connect to the database from your local machine or resource. If you are getting this error, check that you have added the machine or resource you are connecting from to the database's list of trusted sources.
I think I fixed it. It's turns out I had a simple config error. My ini file read:
sqlalchemy.default.url = [connection string here]
sqlalchemy.pool_recycle = 1800
The problem is that my environment.py
file declared that the engine would only map keys with the prefix: sqlalchemy.default
so pool_recycle
was ignored.
The solution is to simply change the second line in the ini to:
sqlalchemy.default.pool_recycle = 1800
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With