最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

CentOS7中MySQL连接数被限制为214个的解决方法

来源:动视网 责编:小采 时间:2020-11-09 20:33:13
文档

CentOS7中MySQL连接数被限制为214个的解决方法

CentOS7中MySQL连接数被限制为214个的解决方法:发现问题 最近在项目中遇到一个问题,由于连接数过多,提示 Too many connections ,需要增加连接数。 我在 /etc/my.cnf中修改了: max_connections = 2000 但是, 实际连接数一直被限制在 214: mysql> show variab
推荐度:
导读CentOS7中MySQL连接数被限制为214个的解决方法:发现问题 最近在项目中遇到一个问题,由于连接数过多,提示 Too many connections ,需要增加连接数。 我在 /etc/my.cnf中修改了: max_connections = 2000 但是, 实际连接数一直被限制在 214: mysql> show variab


发现问题

最近在项目中遇到一个问题,由于连接数过多,提示 “Too many connections” ,需要增加连接数。

我在 /etc/my.cnf中修改了:

max_connections = 2000

但是, 实际连接数一直被限制在 214:

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 214 |
+-----------------+-------+
1 row in set

思考

如果我设置连接小于214时,比如 200,那么实际连接数就是 200,也就是说,我的配置文件是没有问题的。

查 MySQL 官方文档,里面说了:

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. Linux or Solaris should be able to support at 500 to 1000 simultaneous connections routinely and as many as 10,000 connections if you have many gigabytes of RAM available and the workload from each is low or the response time target undemanding. Windows is limited to (open tables × 2 + open connections) < 2048 due to the Posix compatibility layer used on that platform.
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.

大概意思是 MySQL 能够支持的最大连接数量受限于操作系统,必要时可以增大 open-files-limit。换言之,连接数与文件打开数有关。

解决方法

[root@sqzr ~]# ulimit -n
1024

可知,操作系统最大文件描述符限制为 1024。

更改 MySQL 在 Linux 的最大文件描述符限制,编辑 /usr/lib/systemd/system/mysqld.service 文件,在文件最后添加:

LimitNOFILE=65535
LimitNPROC=65535

保存后,执行下面命令,使配置生效

$ systemctl daemon-reload
$ systemctl restart mysqld.service

实际连接数到 2000 了,解决

mysql> show variables like "max_connections";
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 2000 |
+-----------------+-------+
1 row in set

参考

https://dev.mysql.com/doc/refman/5.7/en/too-many-connections.html

https://www.oschina.net/question/853151_241231

总结

文档

CentOS7中MySQL连接数被限制为214个的解决方法

CentOS7中MySQL连接数被限制为214个的解决方法:发现问题 最近在项目中遇到一个问题,由于连接数过多,提示 Too many connections ,需要增加连接数。 我在 /etc/my.cnf中修改了: max_connections = 2000 但是, 实际连接数一直被限制在 214: mysql> show variab
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top