【发布时间】:2011-12-11 17:24:55
【问题描述】:
底线第一:如何在 django 中刷新 MySQL 连接?
在出现MySQL server has gone away 错误后,我发现MySQL documentation 和其他来源(here)建议增加wait_timeout MySQL 参数。对我来说,这似乎是一种解决方法而不是解决方案。我宁愿保留一个合理的wait_timeout,并在代码中刷新连接。
错误:
File "C:\my_proj\db_conduit.py", line 147, in load_some_model
SomeModel.objects.update()
File "C:\Python26\lib\site-packages\django-1.3-py2.6.egg\django\db\models\manager.py", line 177, in update
return self.get_query_set().update(*args, **kwargs)
File "C:\Python26\lib\site-packages\django-1.3-py2.6.egg\django\db\models\query.py", line 469, in update
transaction.commit(using=self.db)
File "C:\Python26\lib\site-packages\django-1.3-py2.6.egg\django\db\transaction.py", line 142, in commit
connection.commit()
File "C:\Python26\lib\site-packages\django-1.3-py2.6.egg\django\db\backends\__init__.py", line 201, in commit
self._commit()
File "C:\Python26\lib\site-packages\django-1.3-py2.6.egg\django\db\backends\__init__.py", line 46, in _commit
return self.connection.commit()
OperationalError: (2006, 'MySQL server has gone away')
设置:Django 1.3.0,MySQL 5.5.14,innodb 1.1.8,Python 2.6.6,Win7 64bit
【问题讨论】: