Bottom line first: How do you refresh the MySQL connection in django?
Following a MySQL server has gone away
error I found that MySQL docum
Since Django 1.6, you can use
import django.db
django.db.close_old_connections()
This does basically the same thing as adamsmith's answer except that it handles multiple databases and also honors the CONN_MAX_AGE
setting. Django calls close_old_connections()
automatically before and after each request, so you normally don't have to worry about it unless you have some long-running code outside of the normal request/response cycle.