如何處理: Can not connect to MySQL server. Too many connections
2018-08-05 17:07:52
13848
MySQL報(bào)錯(cuò)Can not connect to MySQL server. Too many connections,報(bào)錯(cuò)很明確,與MySQL的連接數(shù)滿了。mysql最大連接數(shù)默認(rèn)為100,看來有必要改大一點(diǎn)了。
方法:修改配置,然后重啟
vi /etc/m.cnf加入max_connections=1024,然后重啟mysql即可。
需要注意的是有時(shí)候重啟后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依托于操作系統(tǒng),Linux系統(tǒng)必要時(shí)需要增加open-files-limit。萬萬沒想到啊,修改max_connections竟然要修改操作系統(tǒng)最大文件描述符。
vi /usr/lib/systemd/system/mysqld.service加入
LimitNOFILE=50000
重啟MySQL