MySQL-错误1153:max_allowed_packet

1 问题

编码过程中,有个字段使用TEXT无法存储,改用TEXT(65536) 后成功存储,但是导入mysql时报错:

1
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (1153, "Got a packet bigger than 'max_allowed_packet' bytes")

原因:TEXT(65536)为16M,超过了上限max_allowed_packet

2 解决

修改max_allowed_packet值即可,在Mysql命令行运行:

1
2
3
4
5
mysql> set global net_buffer_length=1000000; 
Query OK, 0 rows affected (0.00 sec)

mysql> set global max_allowed_packet=1000000000;
Query OK, 0 rows affected (0.00 sec)

3 参考