我将python连接到mySqL数据库,并从android发送两个双精度值存储在Mysql中,然后我得到了这个错误。
enter code here
Exception in thread :
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 530, in __bootstrap_inner
self.run()
File "C:\Users\ingy\Desktop\New folder (2)\sssssss.py", line 64, in run
self.pacman()
File "C:\Users\ingy\Desktop\New folder (2)\sssssss.py", line 45, in pacman
x.execute("UPDATE location SET x='%s'"%(x1))
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (2006, 'MySQL server has gone away')现在
enter code here
OperationalError: (2013, 'Lost connection to MySQL server during query')发布于 2011-06-23 06:46:13
这就是我所做的,在我们的例子中,它只在最坏的情况下消失一次,并抛出一个不同的错误,所以我们不会得到无限的递归。
def query(self, sql, parameters=None):
cursor = self.db.cursor()
try:
cursor.execute(sql, parameters)
return cursor
except mysql.connector.Error as ex:
if ex.errno == 2006: # mysql has gone away
cursor.close()
self.connect()
return self.query(sql, parameters)
raise ex发布于 2011-06-23 06:35:26
这通常发生在您的应用程序空闲了太长时间并且不与MySQL通信时。您可以执行以下任一操作:
虚拟输出增加mysql服务器连接超时(在您的例子中,wait_timeout)
SELECT 1如果你可以访问MySQL的连接设置,那么一定要使用第一个设置。
https://stackoverflow.com/questions/6447174
复制相似问题