Too many connections解决方法

在工作中,大家或许常常遇到Too many connections这个错误,这时作为DBA想进数据库管理都进不去,是非常尴尬的一件事情。当然有同学说可以修改配置文件,但是修改配置文件是需要重启mysqld的,这在业务繁忙的数据库服务器上是不允许的。所以紧急情况下可以采用如下的方法,比如下面的测试。

[[email protected]01 msb_5_6_19]# ./use
ERROR 1040 (HY000): Too many connections
[[email protected]-server-01 msb_5_6_19]# 

我上面是采用MySQL沙箱环境,关于沙箱环境的简单安装及使用请参看我前面的文章。MySQL Sandbox安装使用
可以看见我上面已经报了错误,提示也非常明显,就是我们配置的连接数太小,现在已经用完了,这时我们刚想进数据库做些操作,那么采用如下方法:

[[email protected]01 ~]# gdb -p $(cat /root/sandboxes/msb_5_6_19/data/mysql_sandbox5619.pid) -ex "set max_connections=500" -batch
[New LWP 27541]
[New LWP 27540]
[New LWP 27539][Thread debugging using libthread_db enabled]
0x00000031152df343 in poll () from /lib64/libc.so.6
[[email protected]-server-01 ~]# 

下面再次登录数据库看看,并查看最大连接数是否已经修改

[[email protected] msb_5_6_19]# ./use
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.6.19-log MySQL Community Server (GPL)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.

mysql [localhost] {msandbox} ((none)) > show variables like ‘max_connections‘;
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 500   |
+-----------------+-------+
1 row in set (0.00 sec)

mysql [localhost] {msandbox} ((none)) > 

在Percona5.5的thread_pool里面提供了2个参数extra_port和extra_max_connections预留额外的连接,预防连接满了以后我们无法进入数据库进行相应的管理。

root@localhost : (none) 23:18:00> show variables like ‘%extra%‘;
+-----------------------+-------+
| Variable_name         | Value |
+-----------------------+-------+
| extra_max_connections | 1     |
| extra_port            | 10086 |
+-----------------------+-------+
2 rows in set (0.00 sec)

root@localhost : (none) 23:18:04> 
[[email protected]01 user_3307]# netstat -nltp | grep 10086
tcp        0      0 0.0.0.0:10086               0.0.0.0:*                   LISTEN      29655/mysqld
[[email protected]-server-01 user_3307]# 

我这里使用了10086端口,以及最大连接数为1。有这么贴心的功能。必须给一个赞

总结:

通常控制最大连接数有两个参数控制max_connections(该实例允许最大的连接数 ),max_user_connections(该实例允许每个用户的最大连接数),通常情况下前期我们就需要规划好多少连接数合适。一般情况下建议不要超过300。因为MySQL在连接数上升的情况下性能下降非常厉害,如果需要大量连接,这时可以引入thread_pool。所以我们需要保持一个原则:系统创建的用户(给应用使用用户)数* max_user_connections  < max_connections。这样就不会发生文章开始说的问题。

参考资料

http://www.mysqlperformanceblog.com/2010/03/23/too-many-connections-no-problem/

http://www.percona.com/doc/percona-server/5.5/performance/threadpool.html

Too many connections解决方法

时间: 2024-08-01 09:54:49

Too many connections解决方法的相关文章

[转]Oracle 10g及pro*c相关问题及解决方法(转)

Oracle 10g及pro*c相关问题及解决方法 2008年08月21日 星期四 上午 11:21 最近一直在进行ORACLE 10g和PRO*C的学习. 其中遇到了不少的问题: 现列于此,已备他用. [注:我的linux版本是RHEL 5,Oracle版本是10g] 1.在ORACLE 10g 安装准备的过程中:缺少libXp.so.6依赖 上网搜过不少文章,但是都不是很好的解决 我自己摸索出一个解决方法: 在RHEL5的安装盘中找到libXp-1.0.0-8.i386.rpm,进行安装后,

oracle配置监听图形界面不出来解决方法

ROOT用户下,执行 xhost +   然后再切换到oracle用户运行netca DISPLAY 在Linux/Unix类操作系统上, DISPLAY用来设置将图形显示到何处. 直接登陆图形界面或者登陆命令行界面后使用startx启动图形, DISPLAY环境变量将自动设置为:0:0, 此时可以打开终端, 输出图形程序的名称(比如xclock)来启动程序, 图形将显示在本地窗口上, 在终端上输入printenv查看当前环境变量, 输出结果中有如下内容:DISPLAY=:0.0使用xdpyin

Vs2015 win10虚拟机启动问题:无法设置UDP端口 解决方法 合集(转载)

刚装的vs2015 社区版 出现这个问题,wp8.1和win10m模拟器都无法启动,找了好久找到的解决方案,放这儿供大家参考,免得大家像我一样走弯路: Windows Phone emulator not starting (couldn`t setup the UDP port) After updating Windows 10 to build 10061 windows phone emulators (all 8.1 and 10) stopped starting. I get th

MySQL连接数超过限制的解决方法

最近网站出现 User 数据库名称 has already more than 'max_user_connections' active connections 的报错,网站瘫痪.有必要研究下这个问题. max_user_connections 是 MySQL 用户连接数的最大值设置,整段语句的意思是:服务器的 MySQL 的最大连接数参数设置不足.解决方法:修改 MySQL 安装目录下 my.ini 或者 my.cnf 文件内的 max_user_connections 参数的数值,重启 M

VMware Network Adapter VMnet1和VMnet8 被归入[未识别的网络-公用网络]的解决方法(转录的)

系统: Windows7 x64 虚拟软件: VMware Workstation 7.1.3 情况:VMware Network Adapter VMnet1和VMnet8 被防火墙认定为[未识别的网络-公用网络],阻隔,无法使用端口映射,虚拟机的80端口无法传入,数据包只能出不能入.且公用网络被限制不能修改为家庭或工作网络. 解决方法:参考VMware的知识库文章 [http://kb.vmware.com/selfservice/microsites/search.do?language=

Adobe Dreamweaver CC MySQL连接 报404错误的解决方法

Adobe Dreamweaver CC MySQL连接时总报404报错,并给以下两个提示: 1) 在该服务器机器上没有测试服务器运行. 2) 为该站点指定的测试服务器没有映射到http://localhost/_mmServerScripts/MMHTTPDB.phpURL.请确认url前缀映射到了你站点的根上. 网上翻了一堆网站,折腾了两三天,发现可以按如下方法解决: 1)首先要在http://localhost/security/index.php配置mysql的访问密码(我用的是XAMP

【MySQL笔记】mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法

step1:查看 1.1 Mysql命令行里输入"show engines:"查看innoddb数据引擎状态, 1.2 show variables "%_buffer%"里查看innodb_buffer_pool_size的数值,默认是8M(太小,需要改大一点!) step2:找配置文件,修改innodb_buffer_pool_size=64M 2.1 在linux里配置文件是my.cnf,windows里是my.ini(注:不是my-default.ini).

全量恢复gprecoverseg -F出现Unable to connect to database时的相关分析及解决方法

之前有两位朋友碰到过在对greenplum的系统构架更改后,出现全量恢复gprecoverseg -F也无法正常运行的情况. 报错信息为Unable to connect to database. Retrying 1 gprecoverseg failed. (Reason='Unable to connect to database and start transaction') exiting... 有幸拷得一份虚拟机上的全部文件,对其进行分析. 发现其实出现这个问题只需要修改pg_cha

Centos6.5下rsync文件同步安装及配置当中遇到的问题及解决方法

实验节点如下: 源节点:192.168.0.111 备份节点:192.168.0.112 ------------------------------以下部分在两个节点上执行1.防火墙开放873端口(两个节点)#  /sbin/iptables -I INPUT -p tcp --dport 873 -j ACCEPT#  /etc/rc.d/init.d/iptables save#  service iptables restart 2.关闭selinux(两个节点)#  vi /etc/s