Jonathan Livni
Jonathan Livni

Reputation: 107212

MySQL variable through django

Is there a way to execute MySQL variable commands through django such as:

SHOW GLOBAL VARIABLES LIKE 'wait_timeout'

or

SET GLOBAL wait_timeout=2147483

Upvotes: 4

Views: 1460

Answers (1)

Jonathan Livni
Jonathan Livni

Reputation: 107212

You should execute custom SQL directly:

from django.db import connection
cursor = connection.cursor()
cursor.execute("SHOW GLOBAL VARIABLES LIKE 'wait_timeout'")
print cursor.fetchone()
cursor.execute("SET GLOBAL wait_timeout=12345")
cursor.execute("SHOW GLOBAL VARIABLES LIKE 'wait_timeout'")
print cursor.fetchone()

produced:

C:\dev>set_var.py
(u'wait_timeout', u'2147483')
(u'wait_timeout', u'12345')

Upvotes: 5

Related Questions