MySQL が max_connections 制限を超える接続を許可するのはなぜですか?

MySQL が max_connections 制限を超える接続を許可するのはなぜですか?

これが私の接続統計です。

mysql> show status like 'Conn%';
+-----------------------------------+-------+
| Variable_name                     | Value |
+-----------------------------------+-------+
| Connection_errors_accept          | 0     |
| Connection_errors_internal        | 0     |
| Connection_errors_max_connections | 0     |
| Connection_errors_peer_address    | 0     |
| Connection_errors_select          | 0     |
| Connection_errors_tcpwrap         | 0     |
| Connections                       | 274   |
+-----------------------------------+-------+

mysql> SHOW VARIABLES LIKE 'max_%';
+----------------------------+----------------------+
| Variable_name              | Value                |
+----------------------------+----------------------+
| max_allowed_packet         | 16777216             |
| max_binlog_cache_size      | 18446744073709547520 |
| max_binlog_size            | 104857600            |
| max_binlog_stmt_cache_size | 18446744073709547520 |
| max_connect_errors         | 100                  |
| max_connections            | 151                  |
| max_delayed_threads        | 20                   |
| max_digest_length          | 1024                 |
| max_error_count            | 64                   |
| max_execution_time         | 0                    |
| max_heap_table_size        | 16777216             |
| max_insert_delayed_threads | 20                   |
| max_join_size              | 18446744073709551615 |
| max_length_for_sort_data   | 1024                 |
| max_points_in_geometry     | 65536                |
| max_prepared_stmt_count    | 16382                |
| max_relay_log_size         | 0                    |
| max_seeks_for_key          | 18446744073709551615 |
| max_sort_length            | 1024                 |
| max_sp_recursion_depth     | 0                    |
| max_tmp_tables             | 32                   |
| max_user_connections       | 0                    |
| max_write_lock_count       | 18446744073709551615 |
+----------------------------+----------------------+

なぜ制限より多くの接続が許可されているのか疑問に思いますmax_connections。mysql はこれ以上の接続を拒否するべきではないのでしょうか、それとも古い接続を徐々に削除するのでしょうか。ログから判断すると後者が正しいようです。

tail -f /var/log/mysql/error.log
2020-12-15T07:21:59.253969Z 60 [Note] Aborted connection 60 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.253979Z 57 [Note] Aborted connection 57 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.253994Z 56 [Note] Aborted connection 56 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.254119Z 58 [Note] Aborted connection 58 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.254136Z 54 [Note] Aborted connection 54 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.254143Z 59 [Note] Aborted connection 59 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.254154Z 61 [Note] Aborted connection 61 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.254565Z 55 [Note] Aborted connection 55 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.254581Z 53 [Note] Aborted connection 53 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)
2020-12-15T07:21:59.254593Z 62 [Note] Aborted connection 62 to db: 'my_db' user: 'my_user' host: 'my_ip' (Got an error reading communication packets)

これは、データが不要になった場合、mysql がいずれにせよこれらを徐々に削除するため、古い接続を閉じても問題ないことを意味しますか?

答え1

同時に処理された接続の数を確認するために見るべきパラメータは最大使用接続数

接続フィールドは、前回の再起動以降の接続のカウンターとして機能します。

接続

MySQL サーバーへの接続試行回数 (成功または失敗)。

最大使用接続数

サーバーの起動以降に同時に使用された接続の最大数。

参照してくださいこのSEの回答そしてドキュメントさらに深く。

答え2

これはアクティブな接続の数ではありません。Connections接続試行が成功したかどうかの数です。Threads_connected数を確認する必要があります。また、mysql ポートを使用してフィルター処理し、接続を確認することもできますnetstat

これはstackoverlowからの同様の投稿。

関連情報