前言

今天同事跟我反应,mysql无法直接连接。

我用mysql workbench去连接,发现此报错:

Host 'x.x.x.x' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'Connection closed by foreign host.

 

原因

同个ip连接mysql时,短期内出现的连接和断裂次数过大而造成的阻塞。

 

解决

三种方法:

  1. 在mysql中重置最大错误连接数

    mysql> flush hosts;   #默认的max_connection_errors=10,可适当调大
    Query OK, 0 rows affected (0.00 sec)
    

    如果mysql有主从或者MGR集群,则主备机器都要执行。

  2. 在配置文件中添加此项,然后重启mysql服务:

    [mysqld]
    max_connect_errors = 1000
    
  3. 在数据库中添加max_connection_errors

    mysql> show variables like '%max_connection_errors%';
    Empty set (0.01 sec)
    
    mysql> set global max_connect_errors = 1000;
    Query OK, 0 rows affected (0.00 sec)
    
posted on 2020-08-05 18:54  eryoung2  阅读(996)  评论(0编辑  收藏  举报