码迷,mamicode.com
首页 > 数据库 > 详细

【转载】How long is “too long” for MySQL Connections to sleep?

时间:2016-07-07 17:26:24      阅读:270      评论:0      收藏:0      [点我收藏+]

标签:

From:http://dba.stackexchange.com/questions/1558/how-long-is-too-long-for-mysql-connections-to-sleep

 

I logged onto my server to check the status of the database and noticed on the SHOW PROCESSLIST;that there are a large number of connections sleeping that are very old.

技术分享What duration should the connection time limit be before the connection should be killed?

How do I set the time limit in MySQL 5.0.51a-3ubuntu5.4?

Note:

I am using PHP 5.2.x and symfony framework 1.2.

shareimprove this question
 

mysqld will timeout DB Connections based on two(2) server options:

  • interactive_timeout
  • wait_timetout

Both are 28800 seconds (8 hours) by default.

You can set these options in /etc/my.cnf

If your connections are persistent (opened via mysql_pconnect) you could lower these numbers to something reasonable like 600 (10 min) or even 60 (1 min). Or, if your app works just fine, you can leave the default. This is up to you.

You must set these as follows in my.cnf (takes effect after mysql restart):

[mysqld]
interactive_timeout=180
wait_timeout=180

If you do not want to restart mysql, then run these two commands:

SET GLOBAL interactive_timeout = 180;
SET GLOBAL wait_timeout = 180;

This will not close the connections already open. This will cause new connections to close in 180 sec.

shareimprove this answer
 
    
so in /etc/my.cnf I would just put wait_timeout=180? – Patrick Mar 3 ‘11 at 22:28
    
@Patrick Yes, but you need to set both interactive_timeout and wait_timeout to 180. I updated my answer for your response. – RolandoMySQLDBA Mar 3 ‘11 at 22:29 
    
This file can be elsewhere dev.mysql.com/doc/refman/5.1/en/option-files.html and these options may not be explicited (write them by yourself) – nicolallias Jun 15 ‘15 at 15:33

【转载】How long is “too long” for MySQL Connections to sleep?

标签:

原文地址:http://www.cnblogs.com/ddddemo/p/5650538.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!