两周前我买了一台新服务器,从那时起,我有时会在连接这台服务器上的数据库时出错。这是重新启动 mysqld 后的错误日志
var/log/mysqld.log:
131206 10:54:37 [ERROR] Error in accept: Too many open files
131206 10:58:53 [ERROR] Error in accept: Too many open files
131206 11:03:09 [ERROR] Error in accept: Too many open files
131206 11:07:25 [ERROR] Error in accept: Too many open files
131206 11:11:41 [ERROR] Error in accept: Too many open files
131206 11:15:58 [ERROR] Error in accept: Too many open files
131206 11:20:14 [ERROR] Error in accept: Too many open files
131206 11:24:30 [ERROR] Error in accept: Too many open files
131206 11:28:46 [ERROR] Error in accept: Too many open files
131206 11:33:02 [ERROR] Error in accept: Too many open files
我该如何解决这个问题?
抱歉我的英语不好。
更新:
你能帮我更新 my.cnf 吗?
[mysqld]
local-infile=0
innodb_file_per_table
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
Linux server.com 2.6.32-279.el6.x86_64 #1 SMP Fri Jun 22 12:19:21 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
PHP 5.3.27 (cli) (built: Nov 28 2013 02:21:29)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
with the ionCube PHP Loader v4.4.4, Copyright (c) 2002-2013, by ionCube Ltd., and
with Zend Guard Loader v3.3, Copyright (c) 1998-2010, by Zend Technologies
mysql Ver 14.14 Distrib 5.5.31, for Linux (x86_64) using readline 5.1
CentOS release 6.4 (Final)
答案1
您的上次更新表明您遇到了打开文件过多的问题。您必须增加 ulimit 以达到最大打开文件数。
我认为默认值是 1024(您可以通过执行来检查ulimit -a
)。通过执行增加此值
ulimit -n 新值
这将为当前正在运行的会话设置一个新值,该值立即生效
或者,如果您希望更改在重启后继续生效,请执行以下操作:以 root 身份编辑文件 /etc/security/limits.conf 并在末尾添加以下两行:
* 软无文件 16000 * 硬盘无文件 20000
上面两行将最大文件句柄数 - nofile - 更改为新设置。