CREATE TABLE test_load
(
a
int(11) DEFAULT NULL,
b
char(80) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8
CREATE DEFINER=xuhuan
@%
PROCEDURE p_load
(count int UNSIGNED)
begin
declare s int unsigned DEFAULT 1;
DECLARE c char(80) DEFAULT REPEAT(‘a’,80);
while s <= count do
insert into test_load select null,c;
set s=s+1;
end while ;
end;
innodb_flush_log_at_trx_commit=1 ;
mysql> call p_load(500000);
Query OK, 1 row affected (3 min 12.15 sec)
mysql> delete from test_load;
Query OK, 500000 rows affected (2.10 sec)
mysql> show global variables like ‘innodb_flush_log_at_trx_commit’;
±-------------------------------±------+
| Variable_name | Value |
±-------------------------------±------+
| innodb_flush_log_at_trx_commit | 0 |
±-------------------------------±------+
mysql> call p_load(500000);
Query OK, 1 row affected (2 min 15.34 sec)
----------------------------------------------*************************************
本来想测试innodb_flush_log_at_trx_commit对事务的影响。
按照《innodb存储引擎》这本书295页的操作。建立上面的表和存储过程后。
call p_load(500000) 后,便会在查询过程中出现lost connection to mysql server during query 的报错。
show global variables like ‘max_allowed_packet’ 当时大小设置的是1M,
于是把max_allowed_packet大小调到16M,可是执行的时候 ,还是会在查询过程中出现该报错。
然后把max_allowed_packet大小调到32M,依旧会在查询过程中报错。
于是想到了 另外一个参数:net_write_timeout
set net_write_timeout=300;
show variables like ‘net_write_timeout’;
call p_load(500000);
可还是报错了。。。
set global key_buffer_size=64M… 报错…
set global sort_buffer_size=2M … 报错…
set global read_buffer_size=2097152 … 报错…
set global read_rnd_buffer_size=2097152 … 报错
-------------------------------------****************************************
好吧。。说明这个问题是和参数没有任何关系的
查看官网:
https://dev.mysql.com/doc/refman/5.7/en/gone-away.html
An INSERT or REPLACE statement that inserts a great many rows can also cause these sorts of errors. Either one of these statements sends a single request to the server irrespective of the number of rows to be inserted; thus, you can often avoid the error by reducing the number of rows sent per INSERT or REPLACE.
当insert或者replace 大量行数据时候也会出现这种类型的错误。这两个操作都是向服务器发送一个单独的请求而不会涉及有多少行需要插入。因此,可以通过减少 insert 或 replace 的行数来避免这种错误。