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

转载请注明出处WangYuheng’s Blog

由于网络连接不稳定,在连接局域网内的mysql开发服务器时,连续多次断开,结果无法连接到mysql服务器,报错内容如下:

Host 'host_name' is blocked because of many connection errors.
Unblock with 'mysqladmin flush-hosts'

这是mysql自带的一种保护机制,如果客户端连续连接失败次数max_connect_errors,超过默认值,则会拒绝客户端继续连接。
可以通过

SHOW VARIABLES LIKE 'max_connect_errors'
    

查看允许连接失败的次数,默认为100次。由于网络不稳,可能会让JDBC等连接很快超过此默认值,可以通过修改此默认值来避免出现连接失败的情形,如

SET GLOBAL max_connect_errors=10000;

如果本机已被拒绝连接,可以通过另一台可连接到mysql服务器的主机执行以下命令

 mysqladmin flush-hosts -h localhost -uroot -p *****
 

此命令会清空所有的hosts缓存信息,执行后即可链接

Best regards
Wang Yuheng