I got this errors when running my scripts that using multiprocessing to speed-up the task.
1 | OperationalError: (2013, ‘Lost connection to MySQL server during query’) |
Apparently, this problems occurs because another process try to open database connection that already opened by Django.
To solve this problem, just close django database connection in your target worker function with:
1 2 | from django import db db.close_connection() |
One response to “Solve Django OperationalError: (2013, ‘Lost connection to MySQL server during query’)”
New django versions now have: close_old_connections() Use it instead.