执行查询时出现此错误
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')
我看了this question,this one和this one以及this one
我看了Doc,我知道我收到此错误,因为我的查询中的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
您是否知道如何避免此错误?