Host 'x.x.x.x’ is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

Host 'x.x.x.x’ is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'

𝓓𝓸𝓷 Lv6

一、现象

应用程序连接mysql数据库报错

image-20250226140412542

二、原因

同一个ip在短时间内产生太多连接,超过了mysql最大连接错误数限制(max_connection_errors),导致数据库连接阻塞

三、解决方法

1.修改错误连接数

max_connect_errors是一个mysql中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码, 当客户端连接服务端超时, 服务端就会给这个客户端记录一次error,当出错的次数达到max_connect_errors的时候,这个客户端就会被锁定, 如果希望重置此计数器的值,则必须重启MySQL服务器或者执行: mysql> FLUSH HOSTS;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
(1)命令临时修改
mysql> show global variables like 'max_connect_error%';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 100 |
+--------------------+-------+
1 row in set (0.00 sec)


mysql> set global max_connect_errors=300;


(2)参数永久修改
# vi /etc/mysql

[mysqld]
max_connect_errors = 300
2.清理缓存,重置计数器
1
2
3
mysqladmin -u root -p flush-hosts 

mysql> flush hosts;
  • Title: Host 'x.x.x.x’ is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
  • Author: 𝓓𝓸𝓷
  • Created at : 2025-02-26 14:35:09
  • Updated at : 2025-03-04 11:39:01
  • Link: https://www.zhangdong.me/mysql-many-connection-errors.html
  • License: This work is licensed under CC BY-NC-SA 4.0.
评论