gpt4 book ai didi

python - Django:异常值(2013, '2013: Lost connection to MySQL server during query',无)

转载 作者:行者123 更新时间:2023-11-29 02:58:39 25 4
gpt4 key购买 nike

最近我将 Django 从 1.6.5 版本升级到 1.7.1 并将 mysql-connector-python 从 1.x 升级到 2.0.2升级后,在我进行查询的大部分时间都会引发 Exception(2013)。

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")

请帮我解决这个问题。

最佳答案

好的。我做了一些挖掘,看起来这是一个 known issue with Django 1.7 and version 2.0.2 of mysql-connector-python.

该错误在 2.0.3 版本中标记为“已解决”,但尚未发布。

编辑:降级到版本 1.2.3 已被 OP 报告为临时解决方案:

pip install -U --allow-external mysql-connector-python mysql-connector-python==1.2.3

关于python - Django:异常值(2013, '2013: Lost connection to MySQL server during query',无),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27309187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com