事件
需要对数据库xxxdb进行备份
执行 mysqldump --databases xxxdb > xxxdb.mysql
报错
mysqldump: Got error: 1016: “Can’t open file: ‘./xxxdb/userio_day6_12_hour.frm’ (errno: 24)” when using LOCK TABLES
检查
perror 24 :
OS error code 24: Too many open files
排查与解决
主要原因就是lock tables时候文件打开句柄太多导致,可以适当调大文件打开数句柄
我这边的环境是调整到65535,然后可以正确执行mysqldump
数据库查看limit文件打开数限制
mysql>SHOW VARIABLES LIKE ‘%open_files_limit%’;
±-----------------±------+
| Variable_name | Value |
±-----------------±------+
| open_files_limit | 1024 |
±-----------------±------+
操作系统查看limit文件打开数限制
ulimit -n 查看open file limits限制
操作系统修改文件打开数
修改/etc/security/limits.conf:
echo ’
* hard nofile 65535
* soft nofile 65535
’ >> /etc/security/limits.conf
重新登录一下shell终端
数据库修改open_files_limit
A: 6.x mysql
在 my.cnf mysqld添加
open_files_limit = 65535
重启mysql服务
B: 7.x mariadb
vim /usr/lib/systemd/system/mariadb.service
找到Service ,添加LimitNOFILE=65535
systemctl --system daemon-reload
systemctl restart mariadb
最终再检查一下:
介绍内容如下: cat /usr/lib/systemd/system/mariadb.service
For example, if you want to increase mariadb’s open-files-limit to 10000,
you need to increase systemd’s LimitNOFILE setting, so create a file named
“/etc/systemd/system/mariadb.service.d/limits.conf” containing:
[Service]
LimitNOFILE=10000