Too many connections

遇到问题

#mysql
ERROR 1040 (HY000): Too many connections

连接mysql时出现Too many connections

分析问题

查询最大连接数:默认最大连接数151
show variables like “%max_con%”;
max_connections 151
查询最大一次连接数:
show status like ‘Max_used_connections’;
Max_used_connections 151

解决问题:

此时需要增大最大连接数:
在线修改:
set global max_connections=xxx;

vim /etc/my.cnf
Max_connections=1024

思考

如果我设置连接小于214时,比如 200,那么实际连接数就是 200,也就是说,我的配置文件是没有问题的。

查 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。
换言之,mysql 的最大连接数还依赖OS的打开文件最大数

设置打开文件最大数
永久修改: 重启生效
方法一:
#vim /etc/security/limits.conf 两行的 * 表示所有的用户,也可以根据需要设置某一个用户,比如www

  • soft nofile 65535
  • hard nofile 65535
    方法二:
    #echo ‘* - nofile 8192’ >>/etc/security/limits.conf

临时生效:
#ulimit -n 8192
#ulimit -n
8192

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值