One MySQL session for python \ django process

If at the beginning of the python \ django program I load a module that executes a raw sql user command like

from django.db import connection cursor = connection.cursor() cursor.execute("SET SESSION wait_timeout=2147483") 

by changing the session variable, will it run for the rest of the program? i.e. a module in the same MySQL session as the rest of the code running in the same python \ django process?

+4
source share
1 answer

Not reliable.

The proper way to do this is to use init_command in the db parameters OPTIONS dictionary:

 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', ... 'OPTIONS': { 'init_command': '"SET SESSION wait_timeout=2147483', }, } } 
+7
source

Source: https://habr.com/ru/post/1382137/


All Articles