咨询热线:4006-75-4006

售前:9:00-23:30    备案:9:00-18:00    技术:7*24h

如何处理: Can not connect to MySQL server. Too many connections

2018-08-05 17:07:52 14408次

MySQL报错Can not connect to MySQL server. Too many connections,报错很明确,与MySQL的连接数满了。mysql最大连接数默认为100,看来有必要改大一点了。

方法:修改配置,然后重启

vi /etc/m.cnf加入max_connections=1024,然后重启mysql即可。

需要注意的是有时候重启后max_connections变成了214,这就很诡异了。
查阅了官方文档:

The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform, the amount of RAM available, how much RAM is used for each connection, the workload from each connection, and the desired response time. Increasing open-files-limit may be necessary. Also see Section 2.5, “Installing MySQL on Linux”, for how to raise the operating system limit on how many handles can be used by MySQL.

 

把上述语句概括起来就是,max_connections依托于操作系统,Linux系统必要时需要增加open-files-limit。万万没想到啊,修改max_connections竟然要修改操作系统最大文件描述符。

vi /usr/lib/systemd/system/mysqld.service加入

LimitNOFILE=50000

重启MySQL


首页
最新活动
个人中心