转自:

MySQL Error Log Has Messages About "Aborted connection ... Communication Packets" (Doc ID 2322952.1)

1. 连接超时的各种原由

1.1 timeouts and errors

There are two classes for the aborted connection messages: timeouts and errors:
1) Got timeout: These messages are usually caused by the value set server-side for interactive_timeout, net_read_timeout, net_write_timeout, wait_timeout.

2) Got an error: These messages are usually caused by abnormal terminated connections or malformed network packets.

Some of the common reasons for these messages are:
     Inactivity connection is timing out after being idle for wait_timeout or interactive_timeout seconds (which depends on whether it is an interactive connection or not).
     Connection is terminated abnormally, for example because the application crashes or do not close the connection explicitly.
     Network delay or outage.
     The row has more data than max_allowed_packet of client. See also Packet Too Large in the Reference Manual.

Note: The messages may start to appear after changing log_warnings to 2 in MySQL 5.6 or earlier or log_error_verbosity to 3 in MySQL 5.7 or later as the messages only are logged at these levels. This does not mean the condition triggering the message did not occur before changing the log level. MySQL 5.7 defaults to log_error_verbosity = 3 which is also the recommended value in 5.7. In MySQL 8.0 the default is reduced to 2 as some important messages that does not report issues have been changed to system level messages that are always logged.

1.2 案例

The four messages, what they mean, and examples of triggering them will be discussed in the remainder of the section.

1)Got Timeout Reading Communication Packets

This message mainly happens when the connection is timing out due to inactivity (Sleep status) for longer than wait_timeout or interactive_timeout seconds. The wait_timeout setting is used when the client/application is considered non-interactive; the interactive_timeout setting is used for clients that are considered interactive, for example using the mysql command-line client in interactive mode.

The message also happens when Server has not got any message from client for more than net_read_timeout seconds for some reason.

An example of triggering the message due to inactivity is:

session 1> select @@global.wait_timeout, @@global.interactive_timeout;

+-----------------------+------------------------------+

| @@global.wait_timeout | @@global.interactive_timeout |

+-----------------------+------------------------------+

|                 28800 |                        28800 |

+-----------------------+------------------------------+

1 row in set (0.00 sec)

session 1> set global interactive_timeout=10;

Query OK, 0 rows affected (0.00 sec)

session 1>select @@global.wait_timeout, @@global.interactive_timeout;

+-----------------------+------------------------------+

| @@global.wait_timeout | @@global.interactive_timeout |

+-----------------------+------------------------------+

|                 28800 |                           10 |

+-----------------------+------------------------------+

1 row in set (0.00 sec)

^^^ Global value of interactive_timeout has been changed to 10 seconds which means new connection will be applied changed value.

shell$ mysql -utest_user --host=192.0.0.1 --prompt='session 2>'

mysql: [Warning] Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 7

Server version: 5.7.20-enterprise-commercial-advanced-log MySQL Enterprise Server - Advanced Edition (Commercial)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

session 2>

^^^ New connection was established.

session 1> show processlist;

+----+-----------+-------------------+------+---------+------+----------+------------------+

| Id | User      | Host              | db   | Command | Time | State    | Info             |

+----+-----------+-------------------+------+---------+------+----------+------------------+

|  3 | root      | localhost         | NULL | Query   |    0 | starting | SHOW PROCESSLIST |

|  7 | test_user | 192.0.2.101:43822 | NULL | Sleep   |    6 |          | NULL             |

+----+-----------+-------------------+------+---------+------+----------+------------------+

2 rows in set (0.00 sec)

session 1> show processlist;

+----+-----------+-------------------+------+---------+------+----------+------------------+

| Id | User      | Host              | db   | Command | Time | State    | Info             |

+----+-----------+-------------------+------+---------+------+----------+------------------+

|  3 | root      | localhost         | NULL | Query   |    0 | starting | SHOW PROCESSLIST |

|  7 | test_user | 192.0.2.101:43822 | NULL | Sleep   |   10 |          | NULL             |

+----+-----------+-------------------+------+---------+------+----------+------------------+

2 rows in set (0.00 sec)

^^^ Connection id 7 was being idle for 10 seconds

session 1> show processlist;

+----+------+-----------+------+---------+------+----------+------------------+

| Id | User | Host      | db   | Command | Time | State    | Info             |

+----+------+-----------+------+---------+------+----------+------------------+

|  3 | root | localhost | NULL | Query   |    0 | starting | SHOW PROCESSLIST |

+----+------+-----------+------+---------+------+----------+------------------+

1 row in set (0.00 sec)

^^^ After 10 seconds of idling, the id 7 was terminated by mysqld
View Code

相关文章: