MySQL数据库报错java.sql.SQLException: null, message from server: “Host ‘192.168.XXX’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’”
问题:
IDEA启动项目时控制台报错:java.sql.SQLException: null, message from server: “Host ‘192.168.XX.XX’ is blocked because of many connection errors; unblock with ‘mysqladmin flush-hosts’”
环境:
在Linux上Docker运行MySQL(5.7)
原因:
同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞;
解决方式:
-
方式一:(自己是通过这种方式解决的)
重启mysql服务即可 即docker restart mysql
-
方式二:
通过命令行进行mysql控制台 即flush hosts
-
方式三:
修改默认的max_connect_errors连接数(mysql 5.6以上默认是100) |
---|
显示默认连接数:show variables like ‘%max_connect_errors%’ |
---|
修改连接数为500:set global max_connect_errors = 500; (基本上同一IP不可能超过500) |
---|
flush privileges |
---|
service mysql restart |
---|