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

[root@mysql-server- msb_5_6_19]# ./use
ERROR (HY000): Too many connections
[root@mysql-server- msb_5_6_19]#

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

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

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

[root@mysql-server-01 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>
[root@mysql-server- user_3307]# netstat -nltp | grep
tcp 0.0.0.0: 0.0.0.0:* LISTEN /mysqld
[root@mysql-server- 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解决方法的更多相关文章

  1. too many connections 解决方法

    最近写javaee项目的时候,mysql报了too many connections的错误,百度的内容有一些有问题,所以我重新写一下我的解决方法. mysql -u root -p 回车输入密码进入m ...

  2. mysql too many connections解决方法

    MySQL提示“too many connections”的解决办法   今天生产服务器上的MySQL出现了一个不算太陌生的错误“Too many connections”.平常碰到这个问题,我基本上 ...

  3. 数据库too many connections 解决方法

    问题:网站后台突然报错了,显示“too many connections........”这是咋回事? 解决: 先罗列几个有用的操作: ① mysql -u root -p  回车输入密码进入mysq ...

  4. mysql too many connections 解决方法

    1.mysql -u root -p 回车输入密码进入mysql   2.show processlist; 查看连接数,可以发现有很多连接处于sleep状态,这些其实是暂时没有用的,所以可以kill ...

  5. 解决mysql 1040错误Too many connections的方法

    从官方文档知道linux上面编译安装的mysql默认的连接为100个,这样对于网站的需求来说是远远不够的. mysql官方告诉我们需要修改max_connections的值,那么我们怎么去修改呢?有两 ...

  6. [bigdata] 启动CM出现 “JDBC Driver class not found: com.mysql.jdbc.Driver” 以及“Error creating bean with name 'serverLogFetcherImpl'”问题的解决方法

    问题:“JDBC Driver class not found: com.mysql.jdbc.Driver”  通过以下命令启动cm [root@hadoop1 ~]# /etc/init.d/cl ...

  7. Centos 7 mysql Buffered warning: Changed limits: max_connections: 214 解决方法

    Everytime I restart MySQL I have this warning: [Warning] Buffered warning: Changed limits: max_conne ...

  8. 安装Mysql提示1045错误解决方法

    MySQL安装提示一下错误 The security settings could not be applied to the database because the connection has ...

  9. Mongo导出数据文件导致错误 Got signal: 6 (Aborted)解决方法

    一哥们要导出一个数据表的数据,结果导出一半,硬盘不够用,卡死了, 然后重启主机,导致mongo启动后进程自动死掉, 报错如下. Mon Oct 28 10:39:02.270 [initandlist ...

随机推荐

  1. rhadoop linear regression 问题

    library(rhdfs) library(rmr2) hdfs.init() hdfs.delete("/user/output/lm.output") map <- f ...

  2. 【Docker】容器操作(转)

    来自:https://www.cnblogs.com/zydev/p/5803461.html 列出主机上的容器 列出正在运行的容器:   docker ps 列出所有容器:  docker ps - ...

  3. Linux内核之旅

    http://www.kerneltravel.net/ Linux内核之旅 Linux Kernel Travel

  4. 十一、K3 WISE 开发插件《VB插件开发如何代码调试 - 步骤讲解》

    =================================== 目录: 1.配置代码调试启动程序kdmain.exe 2.设置断点 3.触发调试 4.变量跟踪 ================ ...

  5. 【连载6】二手电商APP的导购功能与关系链机制分析

    导读:得益于十余年来各种一手电商平台对市场与用户的教育以及共享.分享经济浪潮的兴起,互联网化的二手.闲置商品买卖.置换成为越来越普遍且简单可实现的生活方式. 第三章目录: 三.对比:主流二手电商竞品的 ...

  6. jmeter中split分隔字符

    jmeter中自带了split函数,但是,注意但是,不能使用"-",","等等符合,否则会报错. 没办法,转投入beanshell的怀抱,使用split,发现& ...

  7. 版本控制 version control和团队协作

    这些技术你可能暂时不会用到,但是一旦软件体量变大,开发人数增加,这就带来质变,需要借助一些工具或者技术才能完成这些复杂的工程. 你可以从最简单的情况思考,你可以对任何类型的文件进行版本控制,比如一个p ...

  8. J - Intersection

    来源poj 1410 You are to write a program that has to decide whether a given line segment intersects a g ...

  9. Redhat7.5安装glusterfs4

    redhat7.5自带yum源不包含glusterfs4,下面通过rpm包的方式安装glusterfs4 环境查看 glusterfs官方网站下载rpm包下载地址 https://buildlogs. ...

  10. 洛谷P1908 逆序对【递归】

    题目:https://www.luogu.org/problemnew/show/P1908 题意:给定一个数组,求逆序对个数. 思路: 是一个很经典的题目了.通过归并排序可以求逆序对个数. 现在有一 ...