MySQL [ERROR 2006 MySQL server has gone away] 错误解决方法

当在 MySQL 表中插入一行很大的数据时,会有一条错误 [ERROR 2006 (HY000): MySQL server has gone away].这时,你需要修改 MySQL 的配置文件,把max_allowed_packet值设置大一些.

查看当前max_allowed_packet值:

1
2
3
4
5
6
7
mysql> show variables like 'max_allowed_packet';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| max_allowed_packet | 16777216 |
+--------------------+----------+
1 row in set (0.00 sec)

这是我已经改过的值(16M),之前默认是1M.

修改my.cnf文件:

1
2
# 添加以下配置,自行改变
max_allowed_packet = 16M

最后就是重启 MySQL systemctl restart mysql 就可以了

0%