MySQL 連接出錯 mysqladmin flush-hosts 解決方法

最近新項目升級了mysql版本到8.0,順便也研究了一下,一奈何天不遂人願,沒幾個坑是不可能的,好不容易安裝上了,項目啓動的時候開始報錯 Host is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’

這個的意思是當一個ip連續多次出現錯誤後,mysql就會 中斷這個ip的連接,拋出mysqladmin flush-host

解決方法:

1、提高允許的max_connect_errors數量(治標不治本)

方法1) ​命令行修改
修改max_connection_errors的數量爲1000
mysql -h 123.57.78.101 -P 3306 -uroot -p123456
set global max_connect_errors=1000;
show variables like ‘%max_connect_errors%’;

命令行修改,只是臨時修改,重啓MySQL後會失效;如果需要永久生效,需要在my.cnf配置文件中修改才行!

方法2)配置文件修改
登陸進入Mysql數據庫查看max_connect_errors
mysql -h 你的ip -P 你的端口 -uroot -p123456
show variables like ‘%max_connect_errors%’;
mysql-connection-error-mysqladmin-flush-hosts-solutions-00
max_connect_errors 默認是10 或 100,修改方法如下:
vim /etc/my.cnf
添加一行
max_connect_errors=1000
重啓MySQL,修改纔會生效!
/etc/init.d/mysqld restart
mysql-connection-error-mysqladmin-flush-hosts-solutions-01

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

方法1) 命令修改flush-hosts
/usr/bin/mysqladmin flush-hosts -h 123.57.78.101 -P 3306 -uroot -p123456
備註:其中服務器IP地址,端口號,用戶名,密碼,上面參數都可以根據需要來添加和修改;
配置有master/slave主從數據庫的要把主庫和從庫都修改一遍的
第二步,在數據庫中進行,執行命令如下:
flush hosts;

方法2)重啓數據庫
/etc/init.d/mysqld restart

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章