If at the start of a python\django program I load a module that executes a raw custom sql command such as
from django.db import connection
cursor = connection.cursor()
cursor.execute("SET SESSION wait_timeout=2147483")
thus changing a session variable, will it hold for all the rest of the program run? i.e. is the module in the same MySQL session as the rest of the code running in the same python\django process?
Not reliably.
The correct way to do this is to use init_command
within the OPTIONS
dictionary of the db settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
...
'OPTIONS': {
'init_command': '"SET SESSION wait_timeout=2147483',
},
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With