2014-12-05 65 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

相關問題