Mysql 在Centos7中 修改連接數

摘要

問題項目中,由於連接數過多,提示“Toomanyconnections”,需要增加連接數。我在/etc/my.cnf中修改了:max_connections=2000但是,實際連接數一直被限制在214:mysql>showvariableslike"max_connections";+-----------------+-------+|Variable_name|Value|+-----------------+-------+|max_conne

問題 

項目中,由於連接數過多,提示 “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
。換言之,連接數與文件打開數有關。


解決[[email protected] ~]# 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.htmlhttps://www.oschina.net/question/853151_241231

 

轉自: https://www.aliyun.com/jiaocheng/1111491.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章