未经授权的登录尝试会长期占用 MySQL 连接吗?

未经授权的登录尝试会长期占用 MySQL 连接吗?

我的 MySQL 的并发连接数受到max_connections云提供商变量的限制。目前限制为151连接数。

只有一个 Web 服务器使用此数据库,因此应该足够了。然而,令我惊讶的是,我的服务器目前有 30 多个活动连接:

mysql> show status where `variable_name` = 'Threads_connected';
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| Threads_connected | 34    |
+-------------------+-------+

虽然目前几乎没有任何东西使用它,但我可以用 show processlist 来验证它:(这里只有一个连接)

mysql> show processlist;
+--------+------------+--------------------+------------+---------+------+----------+------------------+-----------+---------------+
| Id     | User       | Host               | db         | Command | Time | State    | Info             | Rows_sent | Rows_examined |
+--------+------------+--------------------+------------+---------+------+----------+------------------+-----------+---------------+
| 272130 | ********** | ****************** | ********** | Query   |    0 | starting | show processlist |         0 |             0 |
+--------+------------+--------------------+------------+---------+------+----------+------------------+-----------+---------------+

我一直在努力寻找剩余 33 个连接的下落,最后我意识到:这些可能是大规模暴力攻击吗?也许有 30-40 个黑客试图猜测我的密码,每个攻击者都会阻止一个线程?

我的假设正确吗?

更新 2021-07-07:添加了更多有关 MySQL 状态的详细信息

mysql> show status where `variable_name` like '%threads%' or `variable_name` like '%connection%';
+-----------------------------------+---------------------+
| Variable_name                     | Value               |
+-----------------------------------+---------------------+
| Connection_errors_accept          | 0                   |
| Connection_errors_internal        | 0                   |
| Connection_errors_max_connections | 0                   |
| Connection_errors_peer_address    | 8                   |
| Connection_errors_select          | 0                   |
| Connection_errors_tcpwrap         | 0                   |
| Connections                       | 482365              |
| Delayed_insert_threads            | 0                   |
| Max_used_connections              | 74                  |
| Max_used_connections_time         | 2021-07-05 09:10:27 |
| Slow_launch_threads               | 0                   |
| Threadpool_idle_threads           | 0                   |
| Threadpool_threads                | 0                   |
| Threads_cached                    | 5                   |
| Threads_connected                 | 36                  |
| Threads_created                   | 2882                |
| Threads_running                   | 1                   |
+-----------------------------------+---------------------+

答案1

  • SHOW PROCESSLIST仅显示运行该命令的用户的连接。请务必以 身份连接以root获取完整列表。“root”实际上比您需要的权限更大;可能还有其他用户(“admin”?)的权限足够大。就 而言GRANT,所有“用户”需要的就是PROCESS

  • 一旦你获得了进程列表,Time就会显示它们连接以来过了多少秒。

  • SHOW STATUS LIKE 'Threads_running';将显示当前有多少个连接处于活动状态。

  • SHOW STATUS LIKE 'Max_used_connections';是高水位线。如果尚未达到max_connections(您提到 151),则您尚未(自重新启动以来)“用尽连接”。

  • 超时时间可能很长,导致连接挂起。

相关内容