2014-12-05 66 views
2

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

请帮我解决这个问题。

+1

我以前从来没有看到数据库引擎。在我刚刚安装的Django 1.7中,它显示'ENGINE':'django.db.backends.mysql' – 2014-12-05 05:14:57

+0

数据库引擎在[本教程]后面配置(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

回答

1

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

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

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

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

mysql连接器-python的确造成了这个问题。版本2.0.3尚未发布,因此我将mysql-connection-python降级到版本1.2.3。它解决了这个问题。非常感谢你。 'pip install -U --allow-external mysql-connector-python mysql-connector-python == 1.2.3' – Nghung 2014-12-05 14:07:57

相关问题