mysql max_connections 总是 4190
项目中,由于连接数过多,提示“Too many connections”,需要增加连接数。我在 /etc/my.cnf中修改了
max_connections = 3000
但是, 一直都是显示的 214
mysql> show variables like "max_connections";
+—————–+——-+
| Variable_name | Value |
+—————–+——-+
| max_connections | 214 |
+—————–+——-+
1 row in set+
修改 /usr/lib/systemd/system/mariadb.service
LimitNOFILE=65535
LimitNPROC=65535
systemctl status mariadb
Warning: mariadb.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
Hint: Some lines were ellipsized, use -l to show in full.
systemctl daemon-reload
systemctl restart mariadb
show variables like ‘%max_connections%’;
extra_max_connections 1
max_connections 3000 —恢复和配置一样
———————————————4190---------------
mysql max_connections 总是 4190
Variable_name Value
max_connections 4190
查mysql open files
show global variables like ‘%open_files_limit%’;
Variable_name Value
open_files_limit 5000
所以max_connections 不管设多大,都小于5000
-----解决
修改本地openfiles值
到/etc/security/limits.conf這個檔案。
/etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
查看本地open files
ulimit -a |grep open
open files (-n) 555550
查看
grep LimitNOFILE /usr/lib/systemd/system/mysqld.service
LimitNOFILE = 5000
修改
grep LimitNOFILE /usr/lib/systemd/system/mysqld.service
LimitNOFILE = 50000
reload
Warning: mysqld.service changed on disk. Run ‘systemctl daemon-reload’ to reload units.
重启
systemctl restart mysqld
验证
grep max_connections /etc/my.cnf
max_connections=32000
show VARIABLES like "max_connections"
Variable_name Value
max_connections 32000
修改值与mysql值一致
暂时还木有人评论,坐等沙发!