1.临时修改,重新登录MySQL后失效:
登录mysql,在命令行中输入临时修改:set global max_connections=1000;
2. 永久修改:
2.1 打开/etc/security/limits.conf:在文档底部加入
* soft noproc 65535
* hard noproc 65535
* soft nofile 65535
* hard nofile 65535
root soft noproc 65535
root hard noproc 65535
root soft nofile 65535
root hard nofile 65535
2.2 打开etc/mysql/mysql.conf.d/mysqld.cnf:修改文档权限,改为可写(sudo chmod 777 etc/mysql/mysql.conf.d/mysqld.cnf),在文件里加入max_connections=1000
若文档中有max_connections直接修改即可,改完后将权限重新改为只读(sudo chmod 644etc/mysql/mysql.conf.d/mysqld.cnf),否则该配置文件不会生效(这也是Mysql数据库不加载mysqld.cnf配置文件的原因);
2.3 打开/lib/systemd/system/mysql.service:在文档中加入
LimitNOFILE=65535
LimitNPROC=65535
2.4 在终端运行:
systemctl daemon-reload
systemctl restart mysql.service
再次进入mysql时,show variables like’max_connections’;就会显示max_connections为1000了,想要改成其他值按第2步修改即可。
(以上2.1-2.3顺序不分先后)