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

问题描述

测试环境项目正常跑的好好地没人去动,莫名其妙的出现了502异常,经过排查发现应用在访问mysql时报错如下:

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

问题定位

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

问题解决

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

mysql -uroot -p

在这里插入图片描述

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链接并且未被关闭导致阻塞

猜你喜欢

转载自blog.csdn.net/qq_29864051/article/details/130128693