【問題解決】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
- react-解決 fetch 跨域問題:Access to fetch at XXX from origin YYY has been blocked by CORS policyReact跨域BloCCORS
- has been blocked by CORS policy跨域問題解決BloCCORS跨域
- Cannot load from short array because "sun.awt.FontConfiguration.head" is nullNull
- Unable to execute SonarScanner analysis: Fail to get bootstrap index from server: Host is unreachable(Host unreachable)AIbootIndexServer
- Host 'xxx' is not allowed to connect to this MySQL server 解決方法MySqlServer
- "ScrollView can host only one direct child"問題解決View
- 問題解決:TNS-12543: TNS:destination host unreachable
- 解決Dcat Admin laravel框架登入報錯問題,(blocked:mixed-content)Laravel框架BloC
- java.sql.SQLException: The server time zone value ‘Öйú±ê׼ʱ¼ä‘ is unrecognized...報錯解決JavaSQLExceptionServerZed
- 解決問題:Variable 'time_zone' can't be set to the value of 'NULL'Null
- vue 新增axios解決post傳引數為null問題VueiOSNull
- 解決SBT下載慢,dump project structure from sbt問題ProjectStruct
- MySQL案例04:Cause: java.sql.SQLException: Could not retrieve transaction read-only status from serverMySqlJavaExceptionServer
- 上手MySQL之解決問題:not allowed to connect to this MySQL serverMySqlServer
- MySQL異常刨析:ata source rejected establishment of connection, message from server: “Too many connectionMySqlServer
- Doris建立表報錯Failed to find enough host with storage medium問題解決AI
- because it is a JDK dynamic proxy that implements 問題JDK
- 【等待事件】SQL*Net message from dblink事件SQL
- Message from debugger: Terminated due to signal 13
- 解決MySql報錯:1130 - Host ‘xxx‘ is not allowed to connect to this MySQL server的方法MySqlServer
- 解決webpack-dev-server代理常切換問題WebdevServer
- Mysql mysql lost connection to server during query 問題解決方法MySqlServer
- 兩款工具解決SQL Server遷移問題DJSQLServer
- 關於解決Server Tomcat v9.0 Server at localhost failed to start的問題ServerTomcatlocalhostAI
- Unity 解決 Because you are not a member of this projectUnityProject
- improve spring integration read message performance from mqSpringORMMQ
- 解決angular安裝 unable to access 'https:github...' Empty reply from serverAngularHTTPGithubServer
- 使用 core.js 解決 GraphQL Mock Server 跨域問題JSMockServer跨域
- MYSQL timestamp NOT NULL插入NULL的報錯問題MySqlNull
- SQL Server常見問題介紹及快速解決建議SQLServer
- [20190622]收集SQLNet Message From Client資訊.txtSQLclient
- atxserver2 怎麼解決 server 多個網路卡的問題Server
- Host 'localhost' is not allowed to connect to this MySQL serverlocalhostMySqlServer
- “Host ‘xxxx‘ is not allowed to connect to this MySQL server“MySqlServer
- centos7 下解決mysql-server找不到安裝包問題CentOSMySqlServer
- SQL Server 2016升級遷移過程中效能問題解決案例SQLServer
- 【能力提升】SQL Server常見問題介紹及快速解決建議SQLServer