MYsql5.23 最大连接数设置不成功
RHEL\CentOS7下MySQL连接数被限制为214个
WayLau'sPersonalSite2015-07-09273阅读
mysqlcentosCentOSMySQL
问题
项目中,由于连接数过多,提示“Toomanyconnections”,需要增加连接数。我在/etc/my.cnf中修改了
max_connections=2000
但是,实际连接数一直被限制在214
mysql>showvariableslike"max_connections";
+-----------------+-------+
|Variable_name|Value|
+-----------------+-------+
|max_connections|214|
+-----------------+-------+
rowinset
MySQLmax_connections总是214。不能设大了?
环境
CentOS7.1
MySQL5.6.25
思考
如果我设置连接小于214时,比如200,那么实际连接数就是200,也就是说,我的配置文件是没有问题的。
查MySQL官方文档,里面说了
ThemaximumnumberofconnectionsMySQLcansupportdependsonthequalityofthethreadlibraryonagivenplatform,theamountofRAMavailable,howmuchRAMisusedforeachconnection,theworkloadfromeachconnection,andthedesiredresponsetime.LinuxorSolarisshouldbeabletosupportat500to1000simultaneousconnectionsroutinelyandasmanyas10,000connectionsifyouhavemanygigabytesofRAMavailableandtheworkloadfromeachislowortheresponsetimetargetundemanding.Windowsislimitedto(opentables×2+openconnections)<2048duetothePosixcompatibilitylayerusedonthatplatform.
Increasingopen-files-limitmaybenecessary.AlsoseeSection2.5,“InstallingMySQLonLinux”,forhowtoraisetheoperatingsystemlimitonhowmanyhandlescanbeusedbyMySQL.
大概意思是MySQL能够支持的最大连接数量受限于操作系统,必要时可以增大open-files-limit。换言之,连接数与文件打开数有关。
解决
执行
[root@emsc~]#ulimit-n
可知,操作系统最大文件描述符限制为1024,在配置文件中添加
open_files_limit=65535
实际上也没有生效
更改MySQL在Linux的最大文件描述符限制,编辑/usr/lib/systemd/system/mysqld.service文件,在文件最后添加:
LimitNOFILE=65535
LimitNPROC=65535
保存后,执行下面命令,使配置生效
$systemctldaemon-reload
$systemctlrestartmysqld.service
实际连接数到2000了,解决
mysql>showvariableslike"max_connections";
+-----------------+-------+
|Variable_name|Value|
+-----------------+-------+
|max_connections|2000|
+-----------------+-------+
rowinset
参考
http://dev.mysql.com/doc/refman/5.7/en/too-many-connections.html
http://www.oschina.net/question/853151_241231