mysql中Toomanyconnections问题怎么处理

这篇文章将为大家详细讲解有关MySQL中Too many connections问题怎么处理,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

六盘水ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:13518219792(备注:SSL证书合作)期待与您的合作!

1、问题展现
应用端登录出现Too many connections报错
mysql中Too many connections问题怎么处理
检查发现mysql数据库服务端已经达到了max_connections上限
mysql中Too many connections问题怎么处理
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name   | Value |
+-----------------+-------+
| max_connections | 1900  |
+-----------------+-------+
1 row in set (0.00 sec)

mysql> show processlist;
已经达到了1900会话数。

thread_pool设置并不能阻止会话数的上升。
mysql> show variables like 'thread_pool%';
+--------------------------------------+-------+
| Variable_name                        | Value |
+--------------------------------------+-------+
| thread_pool_algorithm                | 0     |
| thread_pool_high_priority_connection | 0     |
| thread_pool_max_unused_threads       | 0     |
| thread_pool_prio_kickup_timer        | 1000  |
| thread_pool_size                     | 16    |
| thread_pool_stall_limit              | 6     |
+--------------------------------------+-------+
6 rows in set (0.00 sec)

2、问题处理
重启mysql的服务。重启完mysql服务后,的确mysql的session数下降了,但是很快会话数又上升到了1900。
判断并不是mysql的服务器端的会话没释放,而是application端的会话没释放。
重启application的两台服务器,mysql的会话数恢复正常。

3、结论
先来看看mysql服务器端的会话保持时间:
mysql> show variables like '%wait_timeout%'; 
+--------------------------+----------+ 
| Variable_name | Value | 
+--------------------------+----------+ 
| innodb_lock_wait_timeout | 50 | 
| lock_wait_timeout | 31536000 | 
| wait_timeout | 28800 | 
+--------------------------+----------+ 
3 rows in set (0.00 sec) 

mysql> show variables like '%interactive_timeout%'; 
+---------------------+-------+ 
| Variable_name | Value | 
+---------------------+-------+ 
| interactive_timeout | 28800 | 
+---------------------+-------+ 
1 row in set (0.00 sec) 

interactive_timeout:服务器关闭交互式连接前等待活动的秒数。交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端。又见wait_timeout 
wait_timeout:服务器关闭非交互连接之前等待活动的秒数。在线程启动时,根据全局wait_timeout值或全局interactive_timeout值初始化会话wait_timeout值,取决于客户端类型(由mysql_real_connect()的连接选项CLIENT_INTERACTIVE定义),又见interactive_timeout 
如此看来,两个变量是共同控制的,那么都必须对他们进行修改了。继续深入这两个变量wait_timeout的取值范围是1-2147483(Windows),1-31536000(linux),interactive_time取值随wait_timeout变动,它们的默认值都是28800。 
MySQL的系统变量由配置文件控制,当配置文件中不配置时,系统使用默认值,这个28800就是默认值。要修改就只能在配置文件里修改。Windows下在%MySQL HOME%/bin下有mysql.ini配置文件,打开后添加两个变量,赋值。 

要解决这个问题:
1、Use connection pooling at client side (in MySQL Connector) to reduce the number of active connections between the client and the server. 
是在客户端安装MySQL Connector
2、Improve the application design to reduce the number of active connections needed and to reduce the time the connection has to stay active. 
从应用端去降低并发数,减少每个会话的保持时间
3、Increase the number of connections handled by MySQL server by adjusting max_connections (keep in mind that this consumes additional RAM and is still limited)
在mysql服务器端增加最大连接数设置,不过会消耗大量内存

建议用第二种方法。因为当前应用会话保持时间是10分钟,建议降低这个数值。

关于“mysql中Too many connections问题怎么处理”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

网站题目:mysql中Toomanyconnections问题怎么处理
网页路径:https://www.cdcxhl.com/article46/psjjeg.html

成都网站建设公司_创新互联,为您提供网站维护虚拟主机标签优化网站制作网站策划网站营销

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

h5响应式网站建设