mysql出现unblock with 'mysqladmin flush-hosts'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql出现unblock with 'mysqladmin flush-hosts'相关的知识,希望对你有一定的参考价值。

朋友发来消息,说一个系统应用登录的时候提示连接超时,让帮忙处理一下。
问他应用和数据库是否都正常,回复说数据库好像没有问题,但是应用日志报无法连接数据库。

数据库版本是:5.5.53


让他telnet数据库是否是通的,回复说不通,并发来了信息提示:

# telnet  8.8.9.9 3306
Trying 8.8.9.9...
Connected to 8.8.9.9.
Escape character is ‘^]‘.
gHost ‘kapp‘ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts‘Connection closed by foreign host.

 

可以看出,产生的原因是:

同一个ip在短时间内产生太多(超过mysql数据库max_connect_errors的最大值)中断的数据库连接而导致的阻塞

 

让他查看以下参数并发来结果:

> show variables like ‘max_connect_errors‘;
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 2     |
+--------------------+-------+

  

max_connect_errors是一个MySQL中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码的情况。
max_connect_errors的值与性能并无太大关系,默认是10,不知道为何改为了2。意味着如果某一客户端尝试连接此MySQL服务器,但是失败(如密码错误等等)2次 ,则MySQL会无条件强制阻止此客户端连接。
如果希望重置此计数器的值,则必须重启MySQL服务器或者执行mysql> flush hosts; 命令。当这一客户端成功连接一次MySQL服务器后,针对此客户端的max_connect_errors会清零。
如果max_connect_errors设置过小,则网页可能提示无法连接数据库服务器。

 

以下是解决方案,再贴一下吧。

解决方法1:修改max_connection_errors的值
(1)进入Mysql数据库查看max_connection_errors:
> show variables like ‘%max_connect_errors%‘;
(2)修改max_connection_errors的值:
> set global max_connect_errors = 100;
(3)查看是否修改成功
> show variables like ‘%max_connect_errors%‘;

解决方法2:使用mysqladmin flush-hosts 命令清理一下hosts文件
(1)在查找到的目录下使用命令修改:mysqladmin -u xxx -p flush-hosts
备注: 配置有master/slave主从数据库的要把主库和从库都修改一遍的
或者
> flush hosts;


解决方法3:重启mysqld
也可以在重启之前,在配置文件中将该参数调大。
# vi /etc/my.cnf
max_connect_errors = 100

 





















以上是关于mysql出现unblock with 'mysqladmin flush-hosts'的主要内容,如果未能解决你的问题,请参考以下文章

MairaDB中,MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush

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

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

错误:MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hos(代

mysql host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts

4.canal抽取失败报is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts‘