当前位置: 代码迷 >> 综合 >> Mysql--Host 'xxx' is blocked because of many connection errors;unblock with 'mysqladmin flush-hosts'
  详细解决方案

Mysql--Host 'xxx' is blocked because of many connection errors;unblock with 'mysqladmin flush-hosts'

热度:44   发布时间:2023-11-17 13:02:30.0

 报错信息:

1、后台控制台报错:

2018-12-17 10:41:48.643 ERROR 4768 --- [eate-1259283097] com.alibaba.druid.pool.DruidDataSource   : create connection error, url: jdbc:mysql://192.168.160.129:3306/znbt?autoReconnect=true&useUnicode=true&createDatabaseIfNotExist=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTCcom.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.at sun.reflect.GeneratedConstructorAccessor57.newInstance(Unknown Source) ~[na:na]at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_192]at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_192]at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.Util.getInstance(Util.java:387) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:917) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2163) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2088) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:806) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47) ~[mysql-connector-java-5.1.39.jar:5.1.39]at sun.reflect.GeneratedConstructorAccessor55.newInstance(Unknown Source) ~[na:na]at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_192]at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_192]at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:410) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:328) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:148) ~[druid-1.0.11.jar:1.0.11]at com.alibaba.druid.filter.FilterAdapter.connection_connect(FilterAdapter.java:785) ~[druid-1.0.11.jar:1.0.11]at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:142) ~[druid-1.0.11.jar:1.0.11]at com.alibaba.druid.filter.stat.StatFilter.connection_connect(StatFilter.java:211) ~[druid-1.0.11.jar:1.0.11]at com.alibaba.druid.filter.FilterChainImpl.connection_connect(FilterChainImpl.java:142) ~[druid-1.0.11.jar:1.0.11]at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1377) ~[druid-1.0.11.jar:1.0.11]at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1431) ~[druid-1.0.11.jar:1.0.11]at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:1857) ~[druid-1.0.11.jar:1.0.11]
Caused by: java.sql.SQLException: null,  message from server: "Host '192.168.160.1' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:963) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:896) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:885) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1042) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2253) ~[mysql-connector-java-5.1.39.jar:5.1.39]at com.mysql.jdbc.ConnectionImpl.connectWithRetries(ConnectionImpl.java:2104) ~[mysql-connector-java-5.1.39.jar:5.1.39]... 17 common frames omitted

 

2、Navicat给的提示信息:

 

此时我觉得很奇怪的是我用xshell登录虚拟机,查看mysql服务运行正常 :

 

解决:

1、这一步完毕后就可以访问MySQL了。

Last login: Sun Dec 16 13:39:58 2018 from 192.168.160.1
[root@192 ~]# cd ..
[root@192 /]# ps -ef | grep mysql
mysql      1060      1  0 07:12 ?        00:00:08 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
root       3785   3766  0 10:43 pts/0    00:00:00 grep --color=auto mysql
[root@192 /]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 343
Server version: 5.7.24 MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| znbt               |
+--------------------+
5 rows in set (0.00 sec)mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
mysql> show global variables like '%max_connect_errors%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 100   |
+--------------------+-------+
1 row in set (0.01 sec)mysql> set global max_connect_errors = 1000;
Query OK, 0 rows affected (0.01 sec)mysql> show global variables like '%max_connect_errors%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| max_connect_errors | 1000  |
+--------------------+-------+
1 row in set (0.00 sec)mysql> flush hosts;
Query OK, 0 rows affected (0.01 sec)mysql> 

2、编辑mysql的配置文件:(彻底解决)

vim my.cnf

 

 

  相关解决方案