MySQL大量报错Got timeout reading communication packets,error显示日志如下:

2018-11-14T23:27:01.130760Z 2876756 [Note] Aborted connection 2876756 to db: 'zabbix_db' user: 'zabbix_u' host: '192.168.255.209' (Got timeout reading communication packets)
2018-11-14T23:27:03.437908Z 2874970 [Note] Aborted connection 2874970 to db: 'zabbix_db' user: 'zabbix_u' host: '192.168.255.209' (Got timeout reading communication packets)

当前MySQL主要timeout相关的参数如下:

show session variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 10       |
| innodb_rollback_on_timeout  | ON       |
| interactive_timeout         | 60       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 60      |
| net_write_timeout           | 30      |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| wait_timeout                | 900      |
+-----------------------------+----------+
13 rows in set (0.01 sec)

connect_timeout:默认为10S
wait_timeout:默认是8小时,即28800秒
interactive_timeout:默认是8小时,即28800秒
net_read_timeout:默认是30S
net_write_timeout:默认是60S
如果是认证过程中超时,不管是读还是,都是 connect_timeout;
对于读网络超时,一般是 wait_timeout/interactive_timeout,基本不会是 net_read_timeout(特例是业务用到 LOAD DATA LOCAL FILE);
对于写网络超时,都是 net_write_timeout。
解决方法如下:

set global interactive_timeout=900;
set global net_read_timeout=900;
set global net_write_timeout=900;

再次tail日志,已经无该信息报错了,可以把以上参数加入到my.cnf里面,900根据实际场景设置;

参考文档:
http://mysql.taobao.org/monthly/2017/05/04/
http://cenalulu.github.io/mysql/mysql-timeout/
https://www.cnblogs.com/xiaoboluo768/p/6222862.html

带符号 * 的表示必填项