暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

mysql出现unblock with 'mysqladmin flush-hosts' (解决:flush hosts;)

巴韭特锁螺丝 2021-12-12
160

https://www.cnblogs.com/abclife/p/9469622.html

1、现象:

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

1

2

3

4

5

# 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.








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

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

1

2

3

4

5

6

> 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_connect_errors的值

(1)进入Mysql数据库查看max_connect_errors:

> show variables like '%max_connect_errors%';

(2)修改max_connect_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

或者

> flush hosts;

解决方法3:重启mysqld

也可以在重启之前,在配置文件中将该参数调大。

# vi etc/my.cnf

max_connect_errors = 100








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

 


文章转载自巴韭特锁螺丝,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论