结论/教程:检查当前打开文件数限制:ulimit -n;临时调整:ulimit -n 65535;永久调整Linux系统打开文件数:在/etc/security/limits.conf添加:* soft nofile 65535 * hard nofile 65535;MySQL配置文件my.cnf中设置open_files_limit = 65535;重启MySQL服务:systemctl restart mysqld;解决连接数不足:show variables like 'max_connections'; 设置max_connections=1000;检查too many connections错误日志。
来源1
在Linux系统中,MySQL打开文件描述符不足是常见问题,表现为无法建立新连接或ERROR 24 (Too many open files)。首先使用ulimit -n查看当前限制,通常默认是1024。临时修改:ulimit -n 10000,重启终端生效但重启服务器失效。永久修改编辑/etc/security/limits.conf,添加以下两行:mysql soft nofile 65535 mysql hard nofile 65535。保存后注销登录重新登录生效。
来源2
MySQL中open_files_limit参数控制服务器能打开的最大文件数,包括表缓存、日志等。查看当前值:mysql> show variables like 'open_files_limit';。编辑/etc/my.cnf [mysqld]段添加open_files_limit=65535。系统级限制也要调高,ulimit -n 65535。同时调整table_open_cache=2000,table_definition_cache=1400。修改后重启mysqld服务:service mysqld restart。
来源3
解决MySQL连接数不足,首先增加max_connections参数,在my.cnf添加max_connections = 1000。然后是打开文件数,因为每个连接都需要文件句柄。系统ulimit调整后,还要调/etc/sysctl.conf:fs.file-max = 655360,sysctl -p生效。MySQL用户pam限制:/etc/pam.d/login添加session required pam_limits.so。重启后监控:netstat -an | grep 3306 | wc -l。
来源4
步骤1:vi /etc/security/limits.conf 添加 * soft nofile 65535 * hard nofile 65535 mysql soft nofile 65535 mysql hard nofile 65535。步骤2:vi /etc/my.cnf [mysqld] open_files_limit=10000。步骤3:vi /etc/pam.d/sshd,取消注释session required pam_limits.so。步骤4:重启sshd和mysqld。验证:mysql> SHOW VARIABLES LIKE 'open_files_limit'; ulimit -a | grep open。
来源5
CentOS 7调整打开文件数:systemd限制编辑/etc/systemd/system/mysqld.service,在[Service]添加LimitNOFILE=65535,然后systemctl daemon-reload && systemctl restart mysqld。my.cnf中open_files_limit必须小于等于系统ulimit。连接数不足时,检查/var/log/mysqld.log中的Too many connections和Too many open files错误。
来源6
优化指南:1. ulimit -n 65535 2. limits.conf * nofile 65535 3. my.cnf open_files_limit=65535 table_open_cache=4096 4. innodb_open_files=65535 5. 重启。监控:mysqladmin -i10 processlist | wc -l 检查连接,lsof -p $(pidof mysqld) | wc -l 检查打开文件。
来源7
FAQ:
Q: 如何临时测试打开文件数调整?
A: ulimit -n 10000,然后mysql连接测试。
Q: 调整后MySQL启动失败?
A: 检查open_files_limit不超过ulimit值,确认my.cnf语法无误。
Q: 连接数仍不足?
A: 调高max_connections,并优化慢查询减少连接占用。
Q: Windows系统怎么调?
A: 修改my.ini open_files_limit,重启服务,无ulimit概念。