最近,我将Django从1.6.5版本升级到1.7.1版本,并将mysql连接器python从1.x升级到2.0.2 升级后,我在查询时大部分时间都会引发异常(2013)。在
Exception Type: InterfaceError
Exception Value: (2013, '2013: Lost connection to MySQL server during query', None)
我已经添加了一些关于“连接最大值”、“等待超时”的设置,但是没有帮助。以下是我的设置:
从命令行:
^{pr2}$来自设置.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
视图.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")
请帮我解决这个问题。在
好吧。我做了一些挖掘,看起来这是一个known issue with Django 1.7 and version 2.0.2 of mysql-connector-python.
这个bug在2.0.3版本中标记为“已解决”,但尚未发布。在
编辑:降级到版本1.2.3已经被OP报告为临时解决方案:
相关问题 更多 >
编程相关推荐