【問題解決】java.sql.SQLException: null, message from server: “Host ‘xxx.xx.xx.xxx‘ is blocked because of
某臺伺服器專案連線不上mysql
java.sql.SQLException: null, message from server: "Host 'xxx.xx.xx.xxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:836)
at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:456)
at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:199)
at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:138)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:353)
at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:201)
at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:473)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:562)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
at com.zaxxer.hikari.HikariDataSource$$FastClassBySpringCGLIB$$eeb1ae86.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
問題原因:將如上錯誤搜尋後會出現很多答案,大體上是說因為請求mysql連線錯誤過多,導致mysql拒絕來自該伺服器ip的連線,多數解決方案如下:
1)修改mysql的最大連線錯誤數(max_connect_errors)
# 檢視某ip地址連結mysql的總連線錯誤數
mysql> select SUM_CONNECT_ERRORS as count from performance_schema.host_cache where ip='xxx.xx.xx.xx';
+-------+
| count |
+-------+
| 116 |
+-------+
1 row in set (0.00 sec)
# 通過修改my.cnf檔案將max_connect_errors連線數設定為1000(預設是100)
mysql> show variables like 'max_connect_errors';
+--------------------+-------+
| Variable_name | Value |
+--------------------+-------+
| max_connect_errors | 1000 |
+--------------------+-------+
1 row in set (0.01 sec)
2)重新重新整理mysql的host許可權
使用命令重新整理
[root@yumaster ~]# /usr/bin/mysqladmin flush-hosts -h ${mysqlIp} -uroot -p
# 不知道位置可通過whereis檢視
[root@yumaster ~]# whereis mysqladmin
mysqladmin: /usr/bin/mysqladmin /usr/share/man/man1/mysqladmin.1.gz
或者使用mysql命令重新整理
mysql> flush hosts;
或者重新給root使用者授權
mysql -u root -p
mysql>use mysql;
mysql>select 'host' from user where user='root';
mysql>update user set host = '%' where user ='root';
mysql>flush privileges;
mysql>select 'host' from user where user='root';
以上一頓操作,結果還是躲不過0-5的結局。
解決方法:作者使用docker部署的後端服務,因為物理機故障問題導致虛擬機器當機,當虛擬機器重啟後發現但凡與mysql關聯的專案都起不來,報了以上錯誤,錯誤在解決方法中也是讓重新整理hosts。
java.sql.SQLException: null, message from server: "Host 'xxx.xx.xx.xxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'"
但是並非如此,作者試用了以上幾種方法都不管用,又通過仔細看日誌發現日誌的列印時間是2018年(當前2020年),
2018-07-26 23:55:10 WARN AIoT-TX-Manager main org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator HHH000342: Could not obtain
2018-07-26 23:55:10 WARN AIoT-TX-Manager main org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext
2018-07-26 23:55:10 INFO AIoT-TX-Manager main org.apache.catalina.core.StandardService Stopping service [Tomcat]
隨即懷疑是因為兩臺伺服器時間不一致導致專案連線mysql失敗。
# mysql伺服器時間
[root@localhost ~]# date
2020年 10月 27日 星期二 18:53:17 CST
# 專案部署伺服器時間
[root@localhost ~]# date
The Jul 26 23:53:17 CST 2018
修改專案伺服器時區與校準為當前時間,問題完美解決。
#刪除當前預設時區的配置檔案,不建議直接刪除(出於操作安全考慮),最好是使用mv命令重新命名
mv /etc/localtime /etc/localtime.bak
#建立軟連線檔案到配置檔案區,替換掉之前刪掉或備份的/etc/localtime 檔案
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
#檢視當前時區
timedatectl
#設定當前時區為上海,因為mysql伺服器時區也是用的上海
timedatectl set-timezone Asia/Shanghai
#安裝時間同步應用
yum install -y ntp
#同步上海授時中心時間
ntpdate ntp.api.bz
#再次檢視時間
date
#開啟定時任務編輯器,設定每天晚上23:59同步時間(也可不設定)
crontab -e
59 23 * * * ntpdate ntp.api.bz
相關文章
- Mysql host is blocked because of many connection errors;unblock解決方法MySqlBloCError
- 【MySQL】Host is blocked because of many connection errorsMySqlBloCError
- 【Mysql】MySql Host is blocked because of many connection errors;MySqlBloCError
- Mysql連線錯誤:Mysql Host is blocked because of many connection errorsMySqlBloCError
- has been blocked by CORS policy跨域問題解決BloCCORS跨域
- 從原始碼解析ERROR 1129 (HY000):Host is blocked because of many connection errors原始碼ErrorBloC
- 【Ubuntu】unknown host問題解決辦法Ubuntu
- REMOTE HOST IDENTIFICATION HAS CHANGED 問題解決REMIDE
- Unable to execute SonarScanner analysis: Fail to get bootstrap index from server: Host is unreachable(Host unreachable)AIbootIndexServer
- react-解決 fetch 跨域問題:Access to fetch at XXX from origin YYY has been blocked by CORS policyReact跨域BloCCORS
- "ScrollView can host only one direct child"問題解決View
- Cannot load from short array because "sun.awt.FontConfiguration.head" is nullNull
- java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized...報錯解決JavaSQLExceptionServerZed
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- Oracle RAC的ORA-12545 Connect failed because target host or object does not exist問題OracleAIObject
- Host 'xxx' is not allowed to connect to this MySQL server 解決方法MySqlServer
- vmware server 解決rac中共享磁碟問題Server
- 安裝sql server遇到問題解決方法SQLServer
- 解決SBT下載慢,dump project structure from sbt問題ProjectStruct
- 解決不能訪問 VMware Server Web Access 的問題ServerWeb
- Doris建立表報錯Failed to find enough host with storage medium問題解決AI
- 問題解決:TNS-12543: TNS:destination host unreachable
- You do not have permission to get URL ‘/’ from this server解決方案Server
- vue 新增axios解決post傳引數為null問題VueiOSNull
- because it is a JDK dynamic proxy that implements 問題JDK
- 解決「問題」,不要解決問題
- SQL*Net message from clientSQLclient
- Unity 解決 Because you are not a member of this projectUnityProject
- MySQL server has gone away 問題的解決方法MySqlServerGo
- 解決SQL Server中CHAR欄位空格問題SQLServer
- sqlserver、oracle資料庫排序空值null問題解決辦法SQLServerOracle資料庫排序Null
- MySQL案例04:Cause: java.sql.SQLException: Could not retrieve transaction read-only status from serverMySqlJavaExceptionServer
- 上手MySQL之解決問題:not allowed to connect to this MySQL serverMySqlServer
- 解決webpack-dev-server代理常切換問題WebdevServer
- 兩款工具解決SQL Server遷移問題DJSQLServer
- master and slave have equal MySQL server UUIDs問題解決ASTMySqlServerUI
- 解決SQL Server 2005中鎖的問題SQLServer
- 解決Sql Server警報的疑難問題(轉)SQLServer