msyql系统变量max_connect_errors

来源:互联网 发布:英文美文软件 编辑:程序博客网 时间:2024/06/07 06:54

一、max_connect_error定义

max_connect_error 从字面意思上理解是最大的连接错误数,网上很多说法大多与暴力破解有关,然而平时我们使用的过程中发现,似乎并不是如此,下面我们实测一下

set global max_connect_errors=2;show variables like 'max_connect_errors';

图一

我们创建一个普通用户来验证:

grant usage on *.* to test@'localhost' identified by '123456';

进行第一次错误登陆:
图二
第二次错误登陆:
图三

然后再用正确的密码登陆:
图四
可以正常登陆,证明该参数与暴力破解没有半毛钱关系,那它这里的error又是什么呢?
我们看看官方的解释:

The value of the max_connect_errors system variable determines how many successive interrupted connection requests are permitted. (See Section 5.1.5, “Server System Variables”.) After max_connect_errors failed requests without a successful connection, mysqld assumes that something is wrong (for example, that someone is trying to break in), and blocks the host from further connections until you issue a FLUSH HOSTS statement or execute a mysqladmin flush-hosts command. 

max_connect_errors的值决定了允许多少连续的被打断的连接,在这之后,mysql认为这些主机是有问题的,加入黑名单,而这份黑名单正是记录在performance_schema.host_cache这张表中。

二、max_connect_errors验证

当连接被中断时,mysql会把这个连接的host记录到perfomance_schema.host_cache这张表中,当着个记录超过max_connect_errors时,mysql认为这个host事有问题的,也就是从这个host上再不能有连接建立,但这个对本地的连接是无效的。
下面我对自己vps进行测试:

telnet **.**.**.** 3306

这里写图片描述
重复两次以上的操作。

select * from performance_schema.host_cache;

这里写图片描述
达到上限2,然后我们正常的用mysql客户端登陆:
这里写图片描述
出现如上错误,验证无误。

原创粉丝点击