背景介绍
在日常使用中发现了一个错误,Host ‘xx.xx.xx.xx’ is blocked because of many connection errors; unblock with 'mysqladmin flush-host
简单查了一下,是因为同一个ip错误连接请求过多导致的。
排查SQL
# 查看最大错误次数
show variables like '%max_connect_errors%';
# 设置最大错误次数
set global max_connect_errors=3;
# 查看超时时间
show variables like 'connect_timeout';
# 设置超时时间
set global connect_timeout=20;
# 当 performance_schema.host_cache.SUM_CONNECT_ERRORS 等于 max_connect_errors时,会报错
select IP,SUM_CONNECT_ERRORS from performance_schema.host_cache;
# 需要执行清理语句
flush hosts
分析问题
# 通过安装插件可以分析问题
# 查看是否安装插件 CONNECTION_CONTROL和CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS
select * from information_schema.plugins where PLUGIN_NAME in ('CONNECTION_CONTROL','CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS');
# 安装插件
INSTALL PLUGIN CONNECTION_CONTROL SONAME 'connection_control.so';
INSTALL PLUGIN CONNECTION_CONTROL_FAILED_LOGIN_ATTEMPTS SONAME 'connection_control.so';
# 插件安装成功后(如果只是为了排查问题,其它参数不要设置,如果有需求可以参考参考官网:https://dev.mysql.com/doc/refman/5.7/en/connection-control-installation.html)
# 执行下面这个SQL,看是否有错误记录,错误记录会记录在information_schema.connection_control_failed_login_attempts表
select * from information_schema.connection_control_failed_login_attempts;
参考原文
原文
https://www.cnblogs.com/gered/p/17546854.html