mysqldump: Got error: 23: Out of resources when opening file
'./db/tbl.MYD' (Errcode: 24) when using LOCK TABLES
Errcode: 24 = EMFILE(進程打開文件描述符耗盡)。
ulimit -n → 1024(預設偏小)。SHOW VARIABLES LIKE 'open_files_limit';。vi /etc/my.cnf
[mysqld]
open_files_limit = 65535 # 建議 65535 或更高
# /etc/security/limits.conf
mysql soft nofile 65535
mysql hard nofile 65535
# /etc/systemd/system/mysqld.service.d/override.conf (systemd)
[Service]
LimitNOFILE=65535
systemctl daemon-reload
systemctl restart mysqld
mysql -e "SHOW VARIABLES LIKE 'open_files_limit';"
-- 應顯示 65535
mysqldump --databases db1 > db1.sql 單庫單檔,減少同時打開表數。--single-transaction 避免 LOCK TABLES(MyISAM 無效)。xtrabackup 或停庫打包 /var/lib/mysql。open_files_limit=65535、table_open_cache=4000。Opened_tables / Open_tables 比率,持續增長表示緩存不足。FLUSH TABLES 釋放閒置句柄(會短暫阻塞)。