一.问题描述
研发跟我反映他们从某个地址访问mysql数据库报类似如下错误
ERROR 1129 (00000): #HY000Host 'aaaa' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
二.问题可能原因
该问题是从某个地址到数据库产生了过多连续的不成功的连接(因为在成功连接之前连接被中断了),详细信息该考如下官方文档中关于max_connect_errors的说明
-
Command-Line Format --max_connect_errors=#
System Variable Name max_connect_errors
Variable Scope Global Dynamic Variable Yes Permitted Values (32-bit platforms, <= 5.6.5) Type integer
Default 10
Min Value 1
Max Value 4294967295
Permitted Values (32-bit platforms, >= 5.6.6) Type integer
Default 100
Min Value 1
Max Value 4294967295
Permitted Values (64-bit platforms, <= 5.6.5) Type integer
Default 10
Min Value 1
Max Value 18446744073709551615
Permitted Values (64-bit platforms, >= 5.6.6) Type integer
Default 100
Min Value 1
Max Value 18446744073709551615
If more than this many successive connection requests from a host are interrupted without a successful connection, the server blocks that host from further connections. You can unblock blocked hosts by flushing the host cache. To do so, issue a
FLUSH HOSTS
statement or execute a mysqladmin flush-hostscommand. If a connection is established successfully within fewer thanmax_connect_errors
attempts after a previous connection was interrupted, the error count for the host is cleared to zero. However, once a host is blocked, flushing the host cache is the only way to unblock it. The default is 100 as of MySQL 5.6.6, 10 before that.
mysql> show variables like 'max_connect_errors';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 500 |
+--------------------+-------+
1 row in set (0.00 sec)
2)查看研发反应的地址 是否达到了max_connect_errors限制
mysql> use performance_schema;
Database changed
mysql> select * from host_cache\G;
*************************** 1. row ***************************
IP: 172.172.xxx.123
HOST: xxxx.xx.xxx.com
HOST_VALIDATED: YES
SUM_CONNECT_ERRORS: <span style="color:#ff0000;">500 >>我们可以看到error计数已经达到设定的500次,所以从这个地址过来的连接请求会被阻塞</span>
COUNT_HOST_BLOCKED_ERRORS: 18832
COUNT_NAMEINFO_TRANSIENT_ERRORS: 34556
COUNT_NAMEINFO_PERMANENT_ERRORS: 0
COUNT_FORMAT_ERRORS: 0
COUNT_ADDRINFO_TRANSIENT_ERRORS: 0
COUNT_ADDRINFO_PERMANENT_ERRORS: 0
COUNT_FCRDNS_ERRORS: 0
COUNT_HOST_ACL_ERRORS: 0
COUNT_NO_AUTH_PLUGIN_ERRORS: 0
COUNT_AUTH_PLUGIN_ERRORS: 0
COUNT_HANDSHAKE_ERRORS: 34809
COUNT_PROXY_USER_ERRORS: 0
COUNT_PROXY_USER_ACL_ERRORS: 0
COUNT_AUTHENTICATION_ERRORS: 0
COUNT_SSL_ERRORS: 0
COUNT_MAX_USER_CONNECTIONS_ERRORS: 0
COUNT_MAX_USER_CONNECTIONS_PER_HOUR_ERRORS: 0
COUNT_DEFAULT_DATABASE_ERRORS: 0
COUNT_INIT_CONNECT_ERRORS: 0
COUNT_LOCAL_ERRORS: 0
COUNT_UNKNOWN_ERRORS: 0
FIRST_SEEN: 2015-11-27 17:48:29
LAST_SEEN: 2016-01-27 10:54:09
FIRST_ERROR_SEEN: 2015-11-27 17:48:29
LAST_ERROR_SEEN: 2016-01-27 10:54:09
mysql> flush hosts;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from host_cache\G;
Empty set (0.00 sec)
ERROR:
No query specified
##执行flush hosts命令后 host_cache表被清空,问题解决。