Re: [flask] [flask-sqlalchemy] MySQL server has gone away
- Sasa Trifunovic
- 2014-04-09 @ 20:36
I had the same problem and tried various configurations changes related to
sqlalchemy and none of them worked(for me), 'server has gone away'
kept randomly occurring. So i had to make it ugly/bad with try/except
inside for loop of 3 attempts. If mysql s "fall asleep" you will get an
error but it will also "wake it up" so that the next attempt will work.
attempt = 0
for attempt in range(3):
firstphoto = Photo.query.filter_by(projectkey=key).first()
On Wed, Apr 9, 2014 at 9:44 PM, Luka Raljević
> Have you set SQLALCHEMY_POOL_RECYCLE as per :
> I set it to 3600 seconds and have no problems with 'MySQL server has gone
> away' error.
> On Tue, Apr 8, 2014 at 11:06 PM, Drew Larson <firstname.lastname@example.org> wrote:
>> I have noticed I am getting 500 Internal Server errors occasionaly and I
>> have tracked it down to my view which tries to get query the database:
>> OperationalError: (OperationalError) (2006, 'MySQL server has gone
away') 'SELECT quiz.id AS quiz_id, quiz.path AS quiz_path, quiz.answer AS
quiz_answer, quiz._start AS quiz__start, quiz._end AS quiz__end \nFROM
quiz \nWHERE quiz._start <= %s AND quiz._end > %s \n LIMIT %s'
(datetime.datetime(2014, 4, 8, 17, 36, 21, 447590),
datetime.datetime(2014, 4, 8, 17, 36, 21, 447590), 1)
>> The MySQL config looks like this # grep 'timeout' /etc/my.cnf
>> wait_timeout = 60 interactive-timeout
>> It looks like SQLAlchemy is trying to use a connection that has been
>> closed by the server, but I don’t know how to fix this. I would prefer to
>> fix this on the Flask side rather than MySQL side.
>> Any pointers would be greatly appreciated. Thanks.
> Luka Raljević
> tel : 095 202 2035