设置mysql最大连接数问题
只修改 /etc/mysql/my.cnf不生效
[mysqld]
max_connections=1001
主要是mysql 的 max_connections 参数 和本身操作系统的open-file-limit有关。
官方文档描述为
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.
以下解决不生产问题
1.修改/etc/security/limits.conf,添加
root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535
2.修改/lib/systemd/system/mysql.service,添加
LimitNOFILE=65535
LimitNPROC=65535
(注:此处路径可能与系统有关, 若不在 /lib/systemd/system 路径下可以确认是否存在于 /usr/lib/systemd/system 路径下)
3、执行命令
systemctl daemon-reload
systemctl restart mysql.service
网友评论