Could not create connection to database server.Attempted reconnect 3 times .Giving up 解决

错误信息

Could not create connection to database server.Attempted reconnect 3 times .Giving up.

message from server: "Host ' X.X.X.X' is blocked because of many connection errors; unblock with ' mysqladmin flush-hosts

原因:

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

解决方案:

查看max_connect_errors参数结果

show variables like 'max_connect_errors';

max_connect_errors是一个MySQL中与安全有关的计数器值,它负责阻止过多尝试失败的客户端以防止暴力破解密码的情况。max_connect_errors的值与性能并无太大关系,默认是10。意味着如果某一客户端尝试连接此MySQL服务器,但是失败(如密码错误等)10次 ,则MySQL会无条件强制阻止此客户端连接。
如果希望重置此计数器的值,则必须重启MySQL服务器或者执行mysql> flush hosts; 命令。当这一客户端成功连接一次MySQL服务器后,针对此客户端的max_connect_errors会清零。
  

解决方法1:修改max_connect_errors的值
(1)进入Mysql数据库查看max_connect_errors: 
> show variables like '%max_connect_errors%'; 
(2)修改max_connect_errors的值: 
> set global max_connect_errors = 100; 
(3)查看是否修改成功
> show variables like '%max_connect_errors%';

解决方法2:使用mysqladmin flush-hosts 命令清理一下hosts文件(不知道mysqladmin在哪个目录下可以使用命令查找:whereis  mysqladmin)
(1)在查找到的目录下使用命令修改:mysqladmin -u xxx -p flush-hosts
或者
> flush hosts;

解决方法3:重启mysqld
也可以在重启之前,在配置文件中将该参数调大。
# vi /etc/my.cnf
max_connect_errors = 100

猜你喜欢

转载自blog.csdn.net/lw112190/article/details/107043762