解决MySQL连接报错Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts

查看日志报错:

com.mysql.cj.exceptions.CJException: null,  message from server: "Host 'xxxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"

首先数据库使用Navicat访问正常,但是应用访问就是不行,即使重启mysql实例也没效果。最后定位到,应该是短时间内产生了大量中断的数据库连接导致,而且失败的连接数量超过了mysql的max_connection_errors的最大值。

1.登录mysql,使用 flush hosts来命令清理hosts文件

flush hosts;

2.调整mysql的最大连接数和最大错误连接数的大小

查看mysql最大错误连接数

show variables like '%max_connect_errors%'

查看mysql最大连接数:

show variables like 'max_connections';

修改连接数大小:

set global max_connections = 1000;
set global max_connect_errors = 1000;

你可能感兴趣的:(mysql,数据库)