Django:异常值(2013年,"2013年:查询期间与MySQL服务器的连接断开",无) [英] Django: Exception Value (2013, '2013: Lost connection to MySQL server during query', None)
问题描述
最近我已将 Django 从1.6.5版本升级到1.7.1,并将 mysql-connector-python 从1.x升级到2.0.2. 升级后,大多数时候查询都会引发Exception(2013).
Recently I have upgraded Django from version 1.6.5 to 1.7.1 and mysql-connector-python from 1.x to 2.0.2 After upgrading, the Exception(2013) is raised most of the time I make a query.
Exception Type: InterfaceError
Exception Value: (2013, '2013: Lost connection to MySQL server during query', None)
我添加了一些有关'CONN_MAX_AGE'和'wait_timeout'的设置,但这无济于事.这是我的设置:
I have added some settings about 'CONN_MAX_AGE', 'wait_timeout' but it does not help. Here are my settings:
从命令行:
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和2.0版的已知问题.2的mysql-connector-python.
Ok. I did some digging around, and it looks like this is a known issue with Django 1.7 and version 2.0.2 of mysql-connector-python.
该错误在2.0.3版中被标记为已解决",但尚未发布.
The bug is marked as "resolved" in version 2.0.3, but is not released yet.
OP已报告降级为1.2.3版,这是一个临时解决方案:
Downgrading to version 1.2.3 has been reported as a temporary solution by OP:
pip install -U --allow-external mysql-connector-python mysql-connector-python==1.2.3
这篇关于Django:异常值(2013年,"2013年:查询期间与MySQL服务器的连接断开",无)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!