Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Current events
Recent changes
Random page
Help
Categories
LemonWiki共筆
Search
Search
Appearance
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
排除 MySQL 技術疑難問題
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== 解決 Host 'xx.xx.xxx.xxx' is blocked because of many connection errors === 錯誤訊息 <pre> Host 'xx.xx.xxx.xxx' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' </pre> 了解問題狀況 (1) 查詢門檻值 MySQL 的機制是:同一個來源主機(依 IP 或 hostname 判斷),累積達到 `max_connect_errors` 設定的次數後,就會自動把這個來源封鎖,拒絕它繼續連線。 <pre> SHOW VARIABLES LIKE 'max_connect_errors'; </pre> 查到的門檻值是 100。 (2) 查詢目前被記錄/封鎖的 host <pre> SELECT IP, HOST, SUM_CONNECT_ERRORS, COUNT_HOST_BLOCKED_ERRORS FROM performance_schema.host_cache ORDER BY SUM_CONNECT_ERRORS DESC; </pre> 確認唯一被鎖的 IP 就是 `xx.xx.xxx.xxx`,`SUM_CONNECT_ERRORS` 剛好等於門檻值 100,且沒有其他 IP 受影響。 解決問題 ⚠️ 提醒:`flush-hosts` / `FLUSH HOSTS` 會清空整個 host cache,不是只清單一 IP。如果查詢結果中還有其他 host 的記錄,執行後會一併重置。若為共用正式環境,執行前建議先跟其他管理者確認。 (1) 到終端機或命令提示字元,輸入指令 <pre> mysqladmin -u root -p flush-hosts </pre> 或 <pre> mysql -u root -p 進入 MySQL SHELL 後再輸入指令:FLUSH HOSTS; </pre> 補充:`FLUSH HOSTS` 語法自 MySQL 8.0.23 起已標示為 deprecated,8.4 版本中移除<ref>[https://dev.mysql.com/doc/refman/8.4/en/performance-schema-host-cache-table.html MySQL :: MySQL 8.4 Reference Manual :: 29.12.22.3 The host_cache Table]</ref><ref>[https://oneuptime.com/blog/post/2026-03-31-mysql-fix-max-connect-errors-blocked-hosts/view How to Fix max_connect_errors and Blocked Hosts in MySQL]</ref>。若環境版本較新,可改用官方建議的替代語法: <pre> TRUNCATE TABLE performance_schema.host_cache; </pre> (2) 執行後驗證 <pre> SELECT IP, HOST, SUM_CONNECT_ERRORS, COUNT_HOST_BLOCKED_ERRORS FROM performance_schema.host_cache ORDER BY SUM_CONNECT_ERRORS DESC; </pre> 結果:沒有資料行(0 rows),代表 host_cache 已清空,先前的連線錯誤紀錄與封鎖狀態都已重設,該 IP 應可正常連線。
Summary:
Please note that all contributions to LemonWiki共筆 are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
LemonWiki共筆:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)