CentOS 7中MySQL連接數(shù)被限制為214個(gè)的解決方法
發(fā)現(xiàn)問(wèn)題
最近在項(xiàng)目中遇到一個(gè)問(wèn)題,由于連接數(shù)過(guò)多,提示 “Too many connections” ,需要增加連接數(shù)。
我在 /etc/my.cnf中修改了:
max_connections = 2000
但是, 實(shí)際連接數(shù)一直被限制在 214:
mysql> show variables like "max_connections"; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 214 | +-----------------+-------+ 1 row in set
思考
如果我設(shè)置連接小于214時(shí),比如 200,那么實(shí)際連接數(shù)就是 200,也就是說(shuō),我的配置文件是沒(méi)有問(wèn)題的。
查 MySQL 官方文檔,里面說(shuō)了:
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 能夠支持的最大連接數(shù)量受限于操作系統(tǒng),必要時(shí)可以增大 open-files-limit。換言之,連接數(shù)與文件打開(kāi)數(shù)有關(guān)。
解決方法
[root@sqzr ~]# ulimit -n 1024
可知,操作系統(tǒng)最大文件描述符限制為 1024。
更改 MySQL 在 Linux 的最大文件描述符限制,編輯 /usr/lib/systemd/system/mysqld.service
文件,在文件最后添加:
LimitNOFILE=65535 LimitNPROC=65535
保存后,執(zhí)行下面命令,使配置生效
$ systemctl daemon-reload $ systemctl restart mysqld.service
實(shí)際連接數(shù)到 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
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
- python 連接數(shù)據(jù)庫(kù)mysql解壓版安裝配置及遇到問(wèn)題
- 查看mysql當(dāng)前連接數(shù)的方法詳解
- Mysql查看最大連接數(shù)和修改最大連接數(shù)的講解
- mysql最大連接數(shù)設(shè)置技巧總結(jié)
- mysql連接數(shù)設(shè)置操作方法(Too many connections)
- 完美解決MySQL通過(guò)localhost無(wú)法連接數(shù)據(jù)庫(kù)的問(wèn)題
- JavaWeb連接數(shù)據(jù)庫(kù)MySQL的操作技巧
- Python 3.x 連接數(shù)據(jù)庫(kù)示例(pymysql 方式)
- php mysql操作mysql_connect連接數(shù)據(jù)庫(kù)實(shí)例詳解
- 總結(jié)MySQL修改最大連接數(shù)的兩個(gè)方式
- Mysql連接數(shù)設(shè)置和獲取的方法
相關(guān)文章
MySQL中存儲(chǔ)的數(shù)據(jù)查詢的時(shí)候如何區(qū)分大小寫(xiě)
這篇文章主要介紹了MySQL中存儲(chǔ)的數(shù)據(jù)查詢的時(shí)候如何區(qū)分大小寫(xiě)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-04-04mysql 主從復(fù)制如何跳過(guò)報(bào)錯(cuò)
這篇文章主要介紹了mysql 主從復(fù)制如何跳過(guò)報(bào)錯(cuò),幫助大家更好的理解和使用MySQL 數(shù)據(jù)庫(kù),感興趣的朋友可以了解下2020-10-10詳解JDBC數(shù)據(jù)庫(kù)鏈接及相關(guān)方法的封裝
這篇文章主要介紹了詳解JDBC數(shù)據(jù)庫(kù)鏈接及相關(guān)方法的封裝的相關(guān)資料,下面是封裝的具體類(lèi),用到了泛型和反射,希望能幫助到大家,需要的朋友可以參考下2017-08-08MySQL多表關(guān)聯(lián)查詢相關(guān)練習(xí)題
這篇文章主要給大家介紹了關(guān)于MySQL多表關(guān)聯(lián)查詢的相關(guān)資料,在MySQL中JOIN語(yǔ)句是實(shí)現(xiàn)多表關(guān)聯(lián)查詢的關(guān)鍵,它可以將多個(gè)表格中符合條件的數(shù)據(jù)連接在一起,從而提供一個(gè)完整的查詢結(jié)果,需要的朋友可以參考下2023-10-10Mysql關(guān)于進(jìn)程中的死鎖和解除鎖問(wèn)題
Mysql 經(jīng)常會(huì)遇到語(yǔ)句或者存儲(chǔ)過(guò)程長(zhǎng)時(shí)間沒(méi)有反應(yīng),大概率就是掛掉了,或者死鎖了,這篇文章主要介紹了Mysql關(guān)于進(jìn)程中的死鎖和解除鎖問(wèn)題,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2023-07-07Mybatis mapper動(dòng)態(tài)代理的原理解析
這篇文章主要介紹了Mybatis mapper動(dòng)態(tài)代理的原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08