1. 程式人生 > 實用技巧 >Ubuntu下更改Mysql中的max_connections和max_user_connections

Ubuntu下更改Mysql中的max_connections和max_user_connections

Ubuntu下更改Mysql中的max_connections和max_user_connections

首先看看自己的系統版本和Mysql版本,看是不是和我的一樣,如果不一樣的話,我並不能保證我的方法一定會成功

系統版本:

uname -a
Linux ubuntu 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

mysql版本:

mysql --version
mysql  Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using  EditLine wrapper

以下操作需要有root許可權

比如說我想將max_connections改為2000,max_user_connections 改為1000

進入/etc/mysql/mysql.conf.d目錄,編輯mysqld.cnf

cd /etc/mysql/mysql.conf.d
vim mysqld.cnf

在最後加上兩行

max_connections        = 2000
max_user_connections   = 1000

重啟mysql

service mysql restart

進入mysql

mysql -u root -p

檢視conn是否發生了變化

show global variables like "%conn%";

在我的電腦上雖然max_user_connections成功變成了1000,但是max_connections卻只為151,如果想讓它變成2000,還需要修改系統配置

cd /etc/systemd/system/multi-user.target.wants
vim mysql.service

在最後面加上這兩行

LimitNOFILE=65535
LimitNPROC=65535

之後重啟服務

systemctl daemon-reload
systemctl restart mysql.service

再次進入mysql,看看成功了沒有?