mysql_exceptions.OperationalError :( 2006,' MySQL服务器已经消失了#39;)

时间:2018-01-08 12:01:31

标签: python mysql mysql-python operationalerror

执行查询时出现此错误

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 questionthis onethis 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

您是否知道如何避免此错误?

0 个答案:

没有答案