最近在论坛里面看到有几个朋友都发帖求助,原因是mysql报错:[ERROR] Error in accept: Two many open files。而且这位朋友还说他并没有同时打开这么多文件,那么这是什么原因呢?
首先,我们需要了解的是,在linux里面打开文件是以文件描述符(FD,file descripter)的形式打开的,每打开一次文件,那么os就分配给你一个文件描述符,对于同一个文件如果有多个进程打开,那么就可以分配多个文件描述符。好了,现在我们回到这个问题上,这位朋友说他并没有一次性打开这么多的文件,怎么会出现这个问题呢?刚才说了,每个进程打开同一个文件都可能分配一个独立的FD,而mysql正是这么做的,每个session开打的数据文件的描述符都是独立的,而对于索引文件则是所有的session共享,
我先将手册里面的原话贴出来:
MySQL is multi-threaded, so there may be many clients issuing queries for a giventable simultaneously. To minimize the problem with multiple client sessions havingdifferent states on the same table, the table is opened independently by eachconcurrent session.
This uses additional memory but normally increases performance.WithMyISAMtables, one extra file descriptor is required for the data file for eachclient that has the table open. (By contrast, the index file descriptor is shared
between all sessions.)
好了,那你现在应该明白了,为什么并没有同时打开那么文件,但是却有那么多的文件描述符。弄清楚问题,那么现在就来解决这个问题。首先是增大table_open_cache,具体用法参考手册上说明,然后根本解决方法是在os上增大mysqld这个线程的最大开打文件数,在linux里面可以通过编辑文件 /etc/security/limits.conf然后里面的信息如下:
# /etc/security/limits.conf
#
#Each line describes a limit for a user in the form:
#
#<domain> <type> <item> <value>
#
#Where:
#<domain> can be:
# - an user name
# - a group name, with @group syntax
# - the wildcard *, for default entry
# - the wildcard %, can be also used with %group syntax,
# for maxlogin limit
#
#<type> can have the two values:
# - "soft" for enforcing the soft limits
# - "hard" for enforcing hard limits
#
#<item> can be one of the following:
# - core - limits the core file size (KB)
# - data - max data size (KB)
# - fsize - maximum filesize (KB)
# - memlock - max locked-in-memory address space (KB)
# - nofile - max number of open files
# - rss - max resident set size (KB)
# - stack - max stack size (KB)
# - cpu - max CPU time (MIN)
# - nproc - max number of processes
# - as - address space limit
# - maxlogins - max number of logins for this user
# - maxsyslogins - max number of logins on the system
# - priority - the priority to run user process with
# - locks - max number of file locks the user can hold
# - sigpending - max number of pending signals
# - msgqueue - max memory used by POSIX message queues (bytes)
# - nice - max nice priority allowed to raise to
# - rtprio - max realtime priority
#
#<domain> <type> <item> <value>
#
这个里面可以对进程需要的很多资源进行配置,比如说我们现在需要就是onfile这个选项open file而且我们有两种配置方式,第一是针对用户组的形式,第二具体用户的形式
比如有mysql用户
mysql soft nofile 131072
上面就限制了mysql用户最大的打开文件数。同时可以通过ulimit -a命令来查看这些信息。
同时需要注意的是,上面配置的用户级别打开FD的个数,系统级别的FD最大打开数可以通过 cat /proc/sys/fs/file-max查看,编辑有两种方式:
1. echo n > /proc/sys/fs/file-max
2. vi /etc/sysctl.conf 然后添加一行 fs.file-max=n 然后使用sysctl -p使其生效
但有时候,我们遇到的不是two many open files 而是 two many connections,这个就是并发的连接数,通过修改参数mysql的max_connections来解决,但是需要注意的是当这个参数增大的时候,同时可能会引发two many open files的问题,原因上面已经解释过了。自己并没有遇到过这个问题,只是简单模拟了一下,如果有错误,欢迎指正。
分享到:
相关推荐
有两种方法 1、修改配置文件文件 修改/etc/my.cnf这个文件,在[mysqld]中新增max_connections=N,如果你没有这个文件请从编译源码中的support-files文件夹中复制你所需要的*.cnf文件为到/etc/my.cnf。我使用的是my-...
主要给大家介绍了关于Mysql错误Too many connections的解决方法,文中通过示例代码介绍的非常详细,对大家学习或者使用Mysql具有一定的参考学习价值,需要的朋友们下面来一起学习学习吧
背景:把mysql换成mysqli时出现,连接数过多,其实际上并不是,原因是我挪动了一下php的sock文件位置导致,因这几个socket修改没有修改完全,于是出现了too many connections ,从mysql里show processlist并没有发现...
- Fix: don't wait indefinitely for trackers and UPnP when shutting down (two new advanced options) -- 2009-04-08: Version 1.8.3 (build 15104) - Change: Installer UI checkbox whether to install or run...
关于mysql 提示too many connections问题解决办法mysql 提示too many connections是由于当前服务器上的mysql连接过多,一方面清当前已有连接,另一方面是改 max_connections (最大连接量)(就是开源节流思想),我...
主要介绍了mysql too many open connections问题解决方法,其实是max_connections配置问题导致,它必须在[mysqld]下面才会生效,需要的朋友可以参考下
SQLyog MySQL GUI Ultimate for Windows - MySQL GUI v12.4.0-0 更新说明:https://blog.webyog.com/adding-option-read-connections-sqlyog-mysql-gui-12-4/ 软件名称:SQLyog MySQL GUI Monitor & Manager & ...
本程序由ASP.NET与ASP写成 文章管理系统使用剑飞4.0管理系统 本程序正常运行需要服务器ASPX、ASP 文章管理后台地址:/...修改诊断系统读取数据库配置路径:guestbook/connections/cong.asp里的/guestbook/#1.mdb
CMake配置生成opencv4的时候,遇到缺少一些模块无法连接服务器进行下载的报错: Couldn't connect to server from the Internet. Perhaps direct connections are not allowed in the current network. To use ...
首先是不知道怎么忽然mysql用命令行,workbench都登录不了,都提示’Access denied for user ‘root’@’localhost’。 数据库卸载重装了几次都不行。好像感觉数据清理不干净。解决的过程遇到的坑,这里记录分享下。...
周公解梦(手机版) 1.01、纯手机版,周公解梦(原版)。2、本地数据库,后台可自行添加更多的梦境。3、全站广告位分别于头部top.asp、底部foot.asp修改即可。...3、修改/Connections/oufudata.asp里面数据库连接地址。
admin\connections\oConn_db.asp 如果在二级目录下使用请修改为 /二级目录名/databases/caifuw.mdb 后台配置里修改上传目录为 /二级目录名/read_write 本程序专为Americaidc美国虚拟主机定制:...
Mysql数据库管理系统优化方案 首先,为了使一个系统更快,最重要的部分就是基础设计,不过有些东西是现有情况下 无法逾越的,比如说系统常见的瓶颈. 我所能想到的: 1:磁盘寻道能力,以高速硬盘(7200转/秒),理论上每秒寻道...
适当的降低max_connections 或调整其他两个数值解决办法在 mysql bin > 中输入 mysql-nt –table_cache=764mysql-nt –innodb_open_files=2048 即可!!table_cache和max_connections 在my.ini 里可调Chang
id /users/:id/tracks /users/:id/playlists /users/:id/followings /users/:id/followers /users/:id/comments/ /users/:id /favorites/ /tracks /playlists /groups/:groupid /comments /me /me/connections
39 案例实战:如何解决经典的Too many connections故障?背后原理是什么.pdf
Thank you for supporting my work and GPL open-source software by donating! Please also rate my application, and tell everyone about it! If bVNC doesn't work for you or you're unhappy, do not write a ...
TCP/IP port redirector with many features for the advanced user. "Like a Swiss Army Knife". * TCP: IP security (and stealth ports on 2000/XP) * TCP: SSL&TLS; using OpenSSL * TCP: tunnelling of ...
5、指定方法和post的数据 python sqlmap.py -u "http://192.168.1.47/page.php" --method "POST" -- data "id=1&cat=2" 6、指定cookie,可以注入一些需要登录的地址 python sqlmap.py -u ...