CentOS7.2 调整mysql数据库最大连接数及系统默认限制说明

系统版本:CentOS7.2 64bit

mysql版本:5.5.47-MariaDB

#############################################################

问题:

CentOS7系统调整数据库最大连接数和之前有所不同,如下:

1.查看mariadb数据库最大连接数,默认为151

或者 执行 usr/bin/mysqladmin -uroot -p variables |grep max_connections

输入数据库密码,而root则替换自己的数据库用户名,查看需要再次输入数据库的密码,即可。


2.配置/etc/my.cnf

 vi /etc/my.cnf 编辑文件,在[mysqld]中加入:max_connections=1000 

[mysqld]新添加一行如下参数:

max_connections=1000

重启mysql服务:service mysqld restart 

重启mysql服务,再次查看mysql数据库最大连接数,可以看到最大连接数是214,并非我们设置的1000。


最大连接数只有214原因

查 MySQL 官方文档,里面说了

The maximum number of connections MySQL can support depends on the quality of the thread library on a given platform, the amount of RAM available, how much RAM is used for each connection, the workload from each connection, and the desired response time. Linux or Solaris should be able to support at 500 to 1000 simultaneous connections routinely and as many as 10,000 connections if you have many gigabytes of RAM available and the workload from each is low or the response time target undemanding. Windows is limited to (open tables × 2 + open connections) < 2048 due to the Posix compatibility layer used on that platform.

Increasing open-files-limit may be necessary. Also see Section 2.5, “Installing MySQL on Linux”, for how to raise the operating system limit on how many handles can be used by MySQL.

大概意思是 MySQL 能够支持的最大连接数量受限于操作系统,必要时可以增大 open-files-limit。换言之,连接数与文件打开数有关。

解决

执行

[root@emsc ~]# ulimit -n
1024

可知,操作系统最大文件描述符限制为 1024, 在 配置文件中添加

open_files_limit = 65535

实际上也没有生效

更改 MySQL 在 Linux 的最大文件描述符限制,编辑 /usr/lib/systemd/system/mysqld.service 文件,在文件最后添加:

LimitNOFILE=65535
LimitNPROC=65535

保存后,执行下面命令,使配置生效

$ systemctl daemon-reload
$ systemctl restart  mysqld.service


因为之前设的最大1000,所以重启后再次查看最大连接数结果为:


到此,Linux环境下的Mysql服务器最大连接数配置修改完成。


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值