max_connect_errors 这个参数控制登陆失败尝试次数,也就是你可以有多少次机会重试登陆;
可以通过status中查看下面两个参数:
Aborted_clients 表示已经成功建立连接的登陆,然后超时断开,或者kill掉的次数;
Aborted_connects 表示失败尝试连接的次数;
例:
session1:
mysql>show global variables like ‘%max_connect_errors%‘;
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 5 |
+--------------------+-------+
开始演示前的数据库原始数据:
mysql>show global status like ‘%abort%‘;
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| Aborted_clients | 0 |
| Aborted_connects | 0 |
+------------------+-------+
session2:
mysql>show processlist;
+----+------+-----------+------+---------+------+----------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+----------+------------------+
| 2 | root | localhost | NULL | Sleep | 8 | | NULL |
| 3 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+------+-----------+------+---------+------+----------+------------------+
干掉现在的连接:
mysql>kill 3;
session1:
可以看到aborted_client变成1,表示原来的一次成功登陆又断开连接了:
mysql>show global status like ‘%abort%‘;
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| Aborted_clients | 1 |
| Aborted_connects | 0 |
+------------------+-------+
session2:
重复这个命令8次:
[[email protected] ~]# mysql -uroot -p111
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
session1:
再回来看aborted_connects变成8 ,表示尝试了8次错误密码登陆
mysql>show global status like ‘%abort%‘;
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| Aborted_clients | 2 |
| Aborted_connects | 8 |
+------------------+-------+
这里有个问题:前面尝试了8次错误密码登陆,为什么 还可以继续尝试登陆呢,为什么max_connetc_errors=5没有生效呢?
这是因为通过mysql -uroot -p111这种本地客户端的网络方式尝试连接,只会提示密码错误,没有失败登陆限制,max_connect_errors这个参数对其他连接方式有限制。
例:
在cmd中:
连续执行6次,会报错,意思就是说尝试次数超过max_connect_errors限制,要想重新登陆,必须执行flush hosts;
C:\Users\cdh>telnet 192.168.91.16 3306
ERROR 1129 (00000):Host ‘192.168.91.1‘ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts‘
mysql>flush hosts;
Query OK, 0 rows affected (0.01 sec)
或者用:
[[email protected] ~]# mysqladmin -uroot -p147258 flush-hosts;