MySQL Errcode: 24 - Too many open files
- 2024-10-17 21:26:00
- 丁国栋
- 原创 340
收到Web应用告警,查看错误日志提示“Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 23 Out of resources when opening file './DATABASE_NAME/TABLE_NAME.MYD' (Errcode: 24 - Too many open files) in /PATH/TO/framework/router.class.php:81”。
登录数据库实例执行 show variables like 'open_files_limit'; 或者查看数据库进程的limits值grep 'Max open files' /proc/$(pgrep mysqld)/limits 都显示打开数是 1024.
但查看系统的nofile配置grep nofile /etc/security/limits.*,是200000,这个值是足够使用。
通过查阅资料,还是systemd服务管理器的原因,要解决这个问题,需要编辑 MySQL systemd service file /lib/systemd/system/mysql.service (这个文件可以通过命令 systemctl status mysql.service |grep Loaded|grep -oP '/.*\.service' 找到),在[service] 下添加 LimitNOFILE=200000,执行 sudo systemctl daemon-reload 和sudo systemctl restart mysql.service 。此时通过查询数据库变量或进程limits就可以验证了,最后再观察业务应用访问情况。