Clean up expired django.contrib.session's in a huge MySQL InnoDB table
While django provides the `django_admin.py cleanup` script, if sessions get out of control sometimes you have to go lower level to get everything cleaned up. If the problem gets out of hand and you hit the resource limits of the machine, it is very difficult to get anything done in the database. Attached is SQL code which was used to cleanup 27GB of expired session data in 3h. Run it like this to make sure it runs to completion: `nohup mysql --user=username --password=password --host=hostname database < delete_expired_sessions.sql` nohup causes the script to run detached from a terminal, so if your session gets disconnected it will keep running.
- mysql
- django.contrib.session
- expire
- innodb