Dear Community,
I keep getting this error, this occurs not all the time, but sometimes.. It work perfectly on my local environment?
Please give me an idea what additional info is needed, thank you
Best regards
Dear Community,
I keep getting this error, this occurs not all the time, but sometimes.. It work perfectly on my local environment?
Please give me an idea what additional info is needed, thank you
Best regards
What kind of code is it that's generating the error? I see you posted something earlier that looked like Django code -- is it happening inside code of yours that's using the Django ORM? Or different code that's talking to MySQL directly?
The reason you're getting the error is that the database closes connections that have been unused for more than five minutes, so the next time you try to use it, it won't work. If you've got code that does some DB stuff, then doesn't do any DB stuff for more than five minutes, then tries to hit the DB again, then you'll get that error.
If you can give the details I mentioned above, I'll be able to recommend the right way to avoid the error.
I'm using Flask and SQLAlchemy. Thank you for poiting me to the clue. It really was that DB closes connection and next connection from code cannot connect to DB. I added this line to the configuration and everything looks good so far.
SQLALCHEMY_POOL_RECYCLE = 250
Ah, sorry about the Django thing -- I must have been confusing you with someone else. Yes, that's exactly the right thing to do to make everything work with Flask/SQLAlchemy. I think what it actually does is make it drop any connections that have been unused for more than 250 seconds from its connection pool, so it won't try to reuse them. You can actually bump that up to 299 if you like -- the MySQL server closes idle connections after 300 seconds.