记一次偶然遇到mysql的max_connection_errors错误

来源:互联网 发布:网络综合布线设计图 编辑:程序博客网 时间:2024/06/05 02:23

前言

打开项目后台发现数据库连接报错,没仔细看大概看了下,噢,是连接数太多了,应该过一会儿就好了,后面发现同事可以访问,我竟然不行,认真看了下这不仅是连接太多,而且还是同一个ip连接太多。懵。

错误关键字

Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’

错误原因

短时间内同一个ip产生了太多数据库连接,超过了mysql 的max_connection_errors的最大值了,ip被拉黑了。

解决办法

[推荐] 使用 mysqladmin flush-hosts 命令清理一下hosts文件(不知道mysqladmin在哪个目录下可以使用命令查找:whereis mysqladmin);

1.在查找到的目录下使用命令修改:/usr/local/bin/mysqladmin flush-hosts -h192.168.x.x -Pxxxx -uroot -pxxxx;

2.配置有master/slave主从数据库的要把主库和从库都修改一遍的

(ps:也可以直接在数据库中执行“flush hosts”)

[不推荐]提高max_connection_errors值:

1.进入Mysql数据库查看max_connection_errors: show variables like ‘%max_connection_errors%’;

2.修改max_connection_errors的数量为1000: set global max_connect_errors = 1000;

3.查看是否修改成功:show variables like ‘%max_connection_errors%’;

原创粉丝点击