"Host 'XXXXX' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"【mysql8】

报错

2020-09-24 17:10:38,630 [C3P0PooledConnectionPoolManager
[identityToken->1hge0yrac1h3dzkqrkiu17|44c03695]-HelperThread-#1] 
WARN  c.m.v.resourcepool.BasicResourcePool 223 - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@60c3133c -- 
Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire 
a needed new resource, we failed to succeed more than the maximum number of 
allowed acquisition attempts (10). Last acquisition attempt exception: 
java.sql.SQLException: null,  message from server: "Host 'XXXXX' 
is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"

原因

同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞;

解决

  • 步骤1:
  • 步骤2:
# mysql -uroot -p
mysql> flush hosts;

或者按照报错日志提示进行操作:

mysqladmin flush-hosts -hxxx -P3306 -uroot -ppwd;

后记

提高允许的max_connection_errors数量

mysql> use mysql;
mysql> show variables like '%max_connect_errors%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 100   |
+--------------------+-------+
1 row in set (0.00 sec)

mysql> set global max_connect_errors = 1000; 

mysql> flush hosts;
  • max_connect_errors
    是一个MySQL中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码的情况。max_connect_errors的值与性能并无太大关系。默认情况下,my.cnf文件中可能没有此行,如果需要设置此数值,手动添加即可。
# vi /etc/my.cnf
max_connect_errors = 1000
  • 配置说明:
    当此值设置为10时,意味着如果某一客户端尝试连接此MySQL服务器,但是失败(如密码错误等等)10次,则MySQL会无条件强制阻止此客户端连接。如果希望重置此计数器的值,则必须重启MySQL服务器或者执行 mysql> flush hosts; 命令。 当这一客户端成功连接一次MySQL服务器后,针对此客户端的max_connect_errors会清零。

  • 影响与错误形式:
    如果max_connect_errors的设置过小,则网页可能提示无法连接数据库服务器;
    而通过SSH的mysql命令连接数据库,则会返回 ERROR 1129 (00000): Host 'gateway' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 错误。

  • 功能与作用:
    一般来说建议数据库服务器不监听来自网络的连接,仅仅通过sock连接,这样可以防止绝大多数针对mysql的攻击;如果必须要开启mysql的网络连接,则最好设置此值,以防止穷举密码的攻击手段。

posted @ 2020-09-24 19:06  邹姣姣  阅读(1310)  评论(0编辑  收藏  举报