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

一.问题描述

    研发跟我反映他们从某个地址访问mysql数据库报类似如下错误

ERROR 1129 (00000): #HY000Host 'aaaa' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'


二.问题可能原因

   该问题是从某个地址到数据库产生了过多连续的不成功的连接(因为在成功连接之前连接被中断了),详细信息该考如下官方文档中关于max_connect_errors的说明

  •  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 than max_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.

##如果从某个地址连续多次发起的数据库连接请求在未成功完成连接之前就被中断,在这样的请求到达一定次数后(max_connect_errors设定值)数据库会阻塞这个地址过来的连接(报错信息如is blocked because of many connection errors)。刷新host cache可以解除阻塞。你可以通过执行flush hosts或者mysqladmin flush-host 命令来刷新 host cache。如果在不成功的连接达到max_connect_errors之前,从该地址成功连接到数据库了,那么该error计数被清零。一旦某个地址因为这个原因连接被阻塞,那么flushing the host cache 是唯一的解决方法。

三. 分析并解决问题
1)查看数据库当前max_connect_errors参数设置
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限制
  我们可以通过performanc_schema数据库下的host_cache表查看
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


3) 解决问题
  从官方文档中我们可以知道,该问题通过flush host cache来解决
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表被清空,问题解决。

你可能感兴趣的:(error,hosts,with,flush,m,of,BLOCKED,because,1129,unblock,mysqlad,00000)