【数据库----MySQL】连接错误过多:is blocked because of many connection errors; unblock with 'mysqladmin flush-ho
·
2019-10-08 20:01:42.935 ERROR [dhc-auth,,,] 14140 --- [reate-149151619] com.alibaba.druid.pool.DruidDataSource : create connection SQLException, url: jdbc:mysql://server-pc:3309/ag_auth_v1?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false&&serverTimezone=UTC, errorCode 1129, state HY000
java.sql.SQLException: null, message from server: "Host '192.168.31.103' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) ~[mysql-connector-java-8.0.11.jar:8.0.11]
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) ~[mysql-connector-java-8.0.11.jar:8.0.11]
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.11.jar:8.0.11]
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) ~[mysql-connector-java-8.0.11.jar:8.0.11]
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444) ~[mysql-connector-java-8.0.11.jar:8.0.11]
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) ~[mysql-connector-java-8.0.11.jar:8.0.11]
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) ~[mysql-connector-java-8.0.11.jar:8.0.11]
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:156) ~[druid-1.1.10.jar:1.1.10]
at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:218) ~[druid-1.1.10.jar:1.1.10]
at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:150) ~[druid-1.1.10.jar:1.1.10]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1560) ~[druid-1.1.10.jar:1.1.10]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1623) ~[druid-1.1.10.jar:1.1.10]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2468) ~[druid-1.1.10.jar:1.1.10]
错误原因:
同一个ip在短时间内产生太多(超过mysql数据库max_connection_errors的最大值)中断的数据库连接而导致的阻塞;
解决办法:
【方法一】
进入数据库将max_connection_errors参数调高,也可以在my.cnf文件中修改不过需要重启MySQL。
查看该属性设置为多大
show global variables like '%max_connect_errors%';
当客户端连接服务端超时(超过connect_timeout), 服务端就会给这个客户端记录一次error,当出错的次数达到max_connect_errors的时候,这个客户端就会被锁定。所以根据业务来尽量把这个值设置大一点,mysql默认值为10,我们可以根据具体需要设置大一点,这里设置为1000.(并非越大越好,越大被攻击时安全性越低)。
set global max_connect_errors=1000;
【方法二】
刷新记录报错host的文件
mysqladmin -uroot -p -h192.168.1.1 flush-hosts
或
mysql>flush hosts;
注意:数据库主从服务器要确定是被哪个MySQL服务拒绝了,刷新对应的服务器即可,不确定的话就都刷新吧。
更多推荐
已为社区贡献2条内容
所有评论(0)