[Mysql-2] 远程连接数据库错误:host 'xxx.xxx' is blocked

时间:2022-07-25
本文章向大家介绍[Mysql-2] 远程连接数据库错误:host 'xxx.xxx' is blocked,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

测试平台突然接口全部报错,赶紧查看日志:

com.github.pagehelper.PageException: java.sql.SQLException: null,  message from server: "Host 'xxx.xxx.xxx.xx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
Connection closing...Socket close.ageException: java.sql.SQLException: null,  message from server: "Host 'xxx.xxx.xxx.xx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"

报错原因

错误原因其实报错信息已经给出:一个IP因为过多的连接错误(超过mysql数据库max_connection_errors的最大值)被数据库服务器阻塞

解决方案

解决方案有多种,可以根据实际情况进行选择:

方法1、清除错误记录 在控制台执行 flush-hosts 即可(或者在navicat等连接工具上进入mysql库,执行该指令)。这个方法直接有效,但如果连接错误继续发生,迟早会再次触发报错。

方法2、修改max_connection_errors

  1. 首先查看该值:show global variables like ‘%max_connect_errors%’;
  1. 然后修改该属性:set global max_connect_errors = 1000
  2. 重复步骤1,可以看到修改生效

方法3、修改配置文件

方法2的修改只是临时方案,要想永久性修改属性值,需要修改mysql的配置文件。如果配置文件里没有这个属性,自己手动添加:max_connect_errors = 1000