发生错误

核心错误为 blocked because of many connection errors

java.sql.SQLException: null, message from server: "Host '117.159.95.59' 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.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1644) ~[druid-1.1.21.jar:1.1.21]
at com.alibaba.druid.pool.DruidAbstractDataSource.createPhysicalConnection(DruidAbstractDataSource.java:1710) ~[druid-1.1.21.jar:1.1.21]
at com.alibaba.druid.pool.DruidDataSource$CreateConnectionThread.run(DruidDataSource.java:2753) ~[druid-1.1.21.jar:1.1.21]
2024-07-24 16:12:22.330 ERROR 24656 --- [eate-1328724647] com.alibaba.druid.pool.DruidDataSource : create connection 
SQLException, url: jdbc:mysql://47.101.42.60:3306/messneger...

错误原因

原因是服务器代码或者是配置文件有问题,导致服务器在不正常的状态下多次重复尝试连接数据库并且连接失败,导致数据库对服务器的host封禁。

解决方法

  1. 该命令会解封所有被阻止的主机,包括指定的IP地址。

  • 使用mysqladmin flush-hosts命令:

  • 在命令行中输入以下命令,并使用具有足够权限的MySQL用户(如root):

mysqladmin -u root -p 'pwd' flush-hosts
  1. 如果在Mysql内部解除限制:

  • 登录进入Mysql

mysql -u root -p 'pwd'
  • 执行命令

FLUSH HOSTS;
  1. 重启Mysql(不推荐)

sudo systemctl restart mysql