CentOS7上MySQL返回 Too many connections

CentOS7上MySQL5.7返回 Too many connections

centos7系统中数据库连接报Too many connections,查了网上一些文章,直接改/etc/my.cnf加入max-connections=3000,无果。
在mysql里输入set GLOBAL max-connections=3000,数值是变了但没有用。
最后发现是CentOS7的systemd限制了服务进程的NOFILE,导致每次启动mysql服务后,查询max-connections一直是214,这个数字可能是默认的最大值吧。解决方法如下:
编辑/usr/lib/systemd/system/mysqld.service,加入:
LimitNOFILE=infinity
LimitMEMLOCK=infinity
搞定。

查看max_connections
进入MySQL,用命令:
$ show variables
查看数据库最大可连接数的变量值:max_connections
查看threads_connected
进入MySQL,用命令:
$ show status
查看当前活动的连接线程变量值:threads_connected

猜你喜欢

转载自blog.csdn.net/qq_31555951/article/details/107089364