问题:
springboot项目运用tomcat启动时,运行日志中报错如下:
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;