查詢Mysql當前的最大連接數
mysql> show variables like "max_connections"; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 150 | +-----------------+-------+ 1 row in set
在文件etc/my.cnf中設置Mysql 最大連接數
[mysqld] max_connections =2000
重啟Mysql 命令
$ systemctl restart mysqld.service
查詢Mysql當前的最大連接數,發現最大連接數是214
mysql> show variables like "max_connections"; +-----------------+-------+ | Variable_name | Value | +-----------------+-------+ | max_connections | 214 | +-----------------+-------+ 1 row in set
更改 MySQL 在 Linux 的最大文件描述符限制,編輯 /usr/lib/systemd/system/mysqld.service 文件,在文件最后添加:
ubuntu16.04 下面位於:/lib/systemd/system/mysql.servive,可以通過find 命令查找
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