mysql连接出错 mysqladmin flush-hosts 解决方法(mysqladmin 刷新主机解除阻塞)

在做redis redlock测试的时候用jmeter发post请求,springboot开始报错 Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’

这个的意思是当一个ip连续多次出现错误后,mysql就会 中断这个ip的连接,抛出mysqladmin flush-host

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

解决方法:

1、修改max_connect_errors数量

1)提高允许的max_connect_errors数量(临时修改)

#修改max_connection_errors的数量为1000
mysql -h 你的ip -P 你的端口 -uroot -p你的密码
set global max_connect_errors=10000;
set global max_connections = 200;
show variables like "max_connections";
show variables like "max_connect_errors";
mysql> set global max_connect_errors=10000;
	   set global max_connections = 200;
Query OK, 0 rows affected (0.04 sec)
Query OK, 0 rows affected (0.04 sec)

mysql> show variables like "max_connections";
	   show variables like "max_connect_errors";
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 200   |
+-----------------+-------+
1 row in set (0.06 sec)
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 10000 |
+--------------------+-------+
1 row in set (0.05 sec)

这只是临时修改,重启MySQL后会失效。

2)如果需要永久生效,需要在配置文件中修改才行!

#登陆进入Mysql数据库查看max_connect_errors
mysql -h 你的ip -P 你的端口 -uroot -p你的密码
show variables like '%max_connect_errors%';
#max_connect_errors 默认是10 或 100,修改方法如下:
vim /etc/my.cnf  #mysql配置文件路径,根据自己的改;windows打开my.ini文件添加,docker进入容器修改同linux后重启容器
max_connect_errors=10000	#添加这一行直接拉满
#重启MySQL,修改才会生效!
#linux
service mysqld restart  
/etc/init.d/mysqld restart
#windows 
net stop mysql #(mysql是服务名)
net start mysql
#docker
docker restart 容器id

2、使用mysqladmin flush-hosts 清理hosts文件

使用mysqladmin flush-hosts 命令清理一下hosts文件
如果不知道mysqladmin在哪个目录下,可以使用命令查找:which mysqladmin

/usr/bin/mysqladmin flush-hosts -h 你的ip -P 你的端口 -uroot -p你的密码
#配置有master/slave主从数据库的要把主库和从库都修改一遍的
#在数据库中进行,执行命令如下:
flush hosts;

猜你喜欢

转载自blog.csdn.net/crayon0/article/details/127299773