MySQL server has gone away报错

时间:2024-03-21 08:05:25

1.最近做插入数据库,然后一直报一个错。mysql server has gone away.(如下图)

MySQL server has gone away报错

查了好多资料,终于解决了。。

1.可能是连接超时。。进入php.ini,修改wait_timeout的值。。有的版本可能没有这两个值,自行添加

wait_timeout=28800
interactive_timeout = 28800

2.可能是查询的结果集超过 max_allowed_packet的大小。。

查看大小

mysql> show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+--------------------+---------+
1 row in set (0.00 sec)

修改大小

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

再次查看

mysql> show global variables like 'max_allowed_packet';
+--------------------+----------+
| Variable_name | Value |
+--------------------+----------+
| max_allowed_packet | 16777216 |
+--------------------+----------+
1 row in set (0.00 sec)

这样再次 执行就没有报错了。。。