最近我从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