Skip to content

Instantly share code, notes, and snippets.

@igniteflow
Created September 3, 2015 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igniteflow/922bbe327478368d2342 to your computer and use it in GitHub Desktop.
Save igniteflow/922bbe327478368d2342 to your computer and use it in GitHub Desktop.
Django: Setting transaction level and autocommit with MySQL
# my.conf
[mysqld]
autocommit = 1
transaction-isolation = READ-COMMITTED
# settings.py
DATABASES = {
...,
'OPTIONS': {
'init_command': 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED',
'read_default_file': 'path/to/my.cnf',
}
}
# this in code somewhere to check settings have been applied
from django.db import connection
import logging
cursor = connection.cursor()
cursor.execute("SHOW VARIABLES LIKE 'tx_isolation'")
logging.info(cursor.fetchone())
cursor.execute("SHOW VARIABLES LIKE 'autocommit'")
logging.info(cursor.fetchone())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment