mariadb错误 host is blocked because of many connection errors; unblock with 'mariadb-admin flush-hosts' 解决办法
简述mariadb连接流程:
- 根据mariadb连接协议,发起握手,在网络层面里
- mariadb服务器在内存上常见客户端连接的数据结构
- 连接认证,检查用户名,密码正确不
- 监听端口,等待命令
原因:
同一个ip在短时间内产生太多(超过mariadb数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞;
max_connect_errors是一个mariadb中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码的情况。
max_connect_errors的值与性能并无太大关系,默认是10。意味着如果某一客户端尝试连接此mariadb服务器,但是失败(如密码错误等等)10次 ,则mariadb会无条件强制阻止此客户端连接。
如果希望重置此计数器的值,则必须重启mariadb服务器或者执行mariadb> flush hosts; 命令。当这一客户端成功连接一次mariadb服务器后,针对此客户端的max_connect_errors会清零。
如果max_connect_errors设置过小,则网页可能提示无法连接数据库服务器。
解决方法:
1. 最简单快捷(治标不治本):
mariadb-admin flush-hosts -u root -p
2. 提高允许的max_connection_errors数量
进入mariadb数据库查看max_connection_errors: show variables like '%max_connection_errors%';
show variables like '%max_connection_errors%';
修改max_connection_errors的数量为1000: set global max_connect_errors = 1000;
set global max_connect_errors = 1000;
查看是否修改成功:show variables like '%max_connection_errors%';
show variables like '%max_connection_errors%';
3. 重启mysqld
也可以在重启之前,在配置文件中将该参数调大。
# vi /etc/my.cnf
max_connect_errors = 100