MySQL最大连接数的问题

在MySQL的源码中,默认最大的连接数是16384

{"max_connections", OPT_MAX_CONNECTIONS, 

    "The number of simultaneous clients allowed.", (gptr*) &max_connections, 

    (gptr*) &max_connections, 0, GET_ULONG, REQUIRED_ARG, 100, 1, 16384, 0, 1, 

    0},

 

 

出现too many connections 的问题,此时已经没办法连接到MySQL上去动态修改max_connections,出现这种问题的可能性有

1 前端应用的问题

可能是由于前端的长连接数过多或者业务量的速增导致连接数比占满的情况

2 自身连接数设置的问题

 

解决的方法

1 设置MySQL的max_connections, interactive_timeout的值,让MySQL来回收这部分连接

2 避免长连接,使用短连接

 

无法登录的处理方法

[root@MASTER_03 ~]# !mysql

mysql -uroot -p

Enter password:

ERROR 1040 (HY000): Too many connections

 

临时的处理方法

[root@MASTER_03 ~]# yum install gdb -y

[root@MASTER_03 ~]# gdb -p $(cat /data/3306/tmp/mysql.pid) -ex "set max_connections=1100" --batch

 

再登录即可

mysql> show global variables like 'max_conn%';

+--------------------+-------+

| Variable_name      | Value |

+--------------------+-------+

| max_connect_errors | 10000 |

| max_connections    | 1100  |

+--------------------+-------+

2 rows in set (0.00 sec)

 

要保持一个原则 max_user_connections  < max_connections  

当然,如果是percona这种版本中,有自带的方法,在Percona5.5的thread_pool里面提供了2个参数extra_port和extra_max_connections预留额外的连接,预防连接满了以后我们无法进入数据库进行相应的管理(具体略)

 

posted on 2016-02-22 10:34  懒睡的猫熊  阅读(1556)  评论(0编辑  收藏  举报