执行查询时出现此错误
File "/usr/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 174, in execute
self.errorhandler(self, exc, value)
File "/usr/lib/python2.7/dist-packages/MySQLdb/connections.py", line 36, in de
faulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away')
我阅读了文档,我知道我收到了这个错误,因为image_name
我的查询太大了
如果您向服务器发送的查询太大,您也可能会收到这些错误。
我为变量的长度设置了一个限制
image_name = (image_name[:180]) if len(image_name) > 180 else image_name
cmd = "UPDATE `banners` SET `checked` = '1',`local_dir` = %s , `image_name` = %s WHERE `unique_id` = %s "
cursor.execute(cmd,[local_addr,image_name,unique_id])
我也设置 max_allowed_packet
了/etc/my.cnf
[mysqld]
max_allowed_packet=16M
您知道如何避免此错误吗?