最近我從1升級的Django從1.6.5版本1.7.1和使用mysql-connector-蟒蛇 .x到2.0.2 升級後,大多數情況下我會進行查詢時引發Exception(2013)。Django的:異常值(2013年, '2013:失去與查詢時MySQL服務器',無)
Exception Type: InterfaceError
Exception Value: (2013, '2013: Lost connection to MySQL server during query', None)
我加入了關於「CONN_MAX_AGE」,「WAIT_TIMEOUT」一些設置,但它並不能幫助。這裏是我的設置:
從命令行:
C:/>pip freeze
Django==1.7.1
South==1.0.1
mysql-connector-python==2.0.2
.....
C:/python -c "import django; print(django.get_version())"
1.7.1
從settings.py:
DATABASES = {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'djangodb',
'USER': 'djangodb',
'PASSWORD': '******',
'HOST': '********',
'PORT': '3306',
'CONN_MAX_AGE' : 600,
}
}
MySQL的設置:
show variables like 'wait_timeout'; #=>28800
show variables like 'net_read_timeout'; #=>30
views.py:
@user_passes_test(lambda u: u.is_superuser)
def db(request, table):
from django.db import connection
cursor = connection.cursor()
if table == "table_status":
cursor.execute("SHOW TABLE STATUS") #No exception 4/5 times
elif table == "processlist":
cursor.execute("SHOW PROCESSLIST") #No exception 4/5 times
elif table == "status":
cursor.execute("SHOW STATUS") #No exception 4/5 times
elif table == "variables":
cursor.execute("SHOW VARIABLES") #Exception is raised 49/50 times
if(cursor):
data = cursor.fetchall()
description = cursor.description
cursor.close()
return render_to_response("myadmin/table.html", {"title": table, "headers":description,"data":data})
else:
return render_to_response("ajax/error404.html")
請幫我解決這個問題。
我以前從來沒有看到數據庫引擎。在我剛剛安裝的Django 1.7中,它顯示'ENGINE':'django.db.backends.mysql' – 2014-12-05 05:14:57
數據庫引擎在[本教程]後面配置(http://bunwich.blogspot.com/2014/02/finally-mysql -connector-that-works-with.html)和[本教程](http://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html) – Nghung 2014-12-05 05:31:41