[英]Django | OperationalError: MySQL Connection not available, disappears on page reload, whats wrong?
I am sometimes getting the following error in Django, which disappears on page reload, I don't know how to reproduce it. 我有时会在Django中收到以下错误,它会在页面重新加载时消失,我不知道如何重现它。 I tried to set wait_timeout to 12 hours in my.cnf , but the error appeared again on mysqld restart
, though did not when I restarted mysqld again, very wierd for me. 我试着在my.cnf中将wait_timeout设置为12小时,但是mysqld restart
出现错误,但是当我再次重启mysqld时没有,对我来说非常奇怪。
Traceback (most recent call last):
File ".../python3.4/site-packages/django/db/backends/__init__.py", line 131, in _cursor
return self.create_cursor()
File ".../python3.4/site-packages/mysql/connector/django/base.py", line 536, in create_cursor
cursor = self.connection.cursor()
File ".../python3.4/site-packages/mysql/connector/connection.py", line 1231, in cursor
raise errors.OperationalError("MySQL Connection not available.")
mysql.connector.errors.OperationalError: MySQL Connection not available.
Do you use django 1.6? 你用django 1.6吗? Maybe there are no requests for particular process for 12 hours? 也许12小时内没有特定流程的请求? Seems like connection was broken by timeout and reopen in next request. 似乎连接被超时中断并在下一个请求中重新打开。 Try to set CONN_MAX_AGE=3600 in database section of django settings file. 尝试在django设置文件的数据库部分设置CONN_MAX_AGE = 3600。 If this value less than wait_timeout in mysql config you prevent connection timeout error. 如果此值小于mysql配置中的wait_timeout,则会阻止连接超时错误。
https://docs.djangoproject.com/en/1.6/ref/settings/#conn-max-age https://docs.djangoproject.com/en/1.6/ref/settings/#conn-max-age
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.