shell> perror 23
Error code 23: File table overflow
shell> perror 24
Error code 24: Too many open files
shell> perror 11
Error code 11: Resource temporarily unavailable
核心原因:mysqld 同時開啟檔案數超過作業系統/進程限制。
| 參數 | 預設 | 調整建議 | 影響 |
|---|---|---|---|
| table_open_cache | 4000 (8.0) / 64 (舊版) | 視實際併發調整,避免過大 | 減少 .frm/.MYD/.MYI 開啟數 |
| max_connections | 151 | 實際峰值 + 余量 | 每連線約開啟 2-3 個檔案 |
# /etc/security/limits.conf
mysql soft nofile 65535
mysql hard nofile 65535
# /etc/sysctl.conf
fs.file-max = 1000000
# systemctl edit mysqld
[Service]
LimitNOFILE=65535
# 編輯 mysqld_safe
ulimit -n 65535 # 取消註解並修改數值
# 登入 mysql shell
SHOW VARIABLES LIKE 'open_files_limit';
# 或查看進程實際限制
cat /proc/$(pidof mysqld)/limits | grep 'Max open files'
ulimit 行為異常,請用 sh mysqld_safe 啟動。docker run --ulimit nofile=65535:65535 ... 或 Dockerfile RUN ulimit -n 65535。Open_files / open_files_limit > 80% 觸發告警。Table_open_cache_misses 快速增長 → 需調大 table_open_cache 或檢查 SQL 開啟過多表。errno 23/24 是資源配額不足的經典信號。現代部署(systemd + 64 位元 OS)下,系統級 LimitNOFILE=65535 + 合理 table_open_cache 即可覆蓋絕多數場景。持續監控開啟檔案比率,提前擴容,避免業務突發中斷。