mysql导入大批量数据出现MySQL server has gone away的解决方法
mysql> show global variables like 'max_allowed_packet';
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 4194304 |
+-
可以看到是4M,然后调大为256M(1024*1024*256)
mysql> set global max_allowed_packet=268435456;
Query OK, 0 rows affected (0.00 sec)mysql> show global variables like 'max_allowed_packet';
+--------------------+-----------+
| Variable_name | Value |
+--------------------+-----------+
| max_allowed_packet | 268435456 |
+--------------------+-----------+
1 row in set (0.00 sec)
注意:
使用set global命令修改 max_allowed_packet 的值,重启mysql后会失效,还原为默认值。
如果想重启后不还原,可以打开 my.cnf 文件,添加 max_allowed_packet = 256M 即可。
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/4046.html