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

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


20down votefavorite

11

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.

mysql mysql-5


shareimprove this question

edited Aug 23 ‘11 at 3:33

RolandoMySQLDBA

103k14132264

asked Mar 3 ‘11 at 20:37

Patrick

1,46461625

 
add a comment

1 Answer

activeoldestvotes


up vote32down voteaccepted

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

edited Dec 13 ‘11 at 22:52

answered Mar 3 ‘11 at 21:22

RolandoMySQLDBA

103k14132264

 

    

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

add a comment

时间: 2024-08-26 23:20:01

【转载】How long is “too long” for MySQL Connections to sleep?的相关文章

【转载】 使用Anemometer基于pt-query-digest将MySQL慢查询可视化

原文地址:使用Anemometer基于pt-query-digest将MySQL慢查询可视化 作者:84223932 本文主要介绍使用Anemometer基于pt-query-digest将MySQL慢查询可视化,因为网上资料相对较少,且都是英文的,遇到报错也没有相关的参考资料,因此写此文. 欢迎转载,请注明作者.出处. 作者:张正 blog:http://space.itpub.net/26355921 QQ:176036317 如有疑问,欢迎联系. 准备条件:1.MySQL开启慢查询 2.安

cacti监控 之 mysql connections

cacti监控mysql的线程,并发,连接情况,缓存使用情况,查询方式等等 wgets https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-monitoring-plugins-1.1.6.tar.gz                                                                                      (截止2017.1.4最新版

MySQL创建用户与授权方法

MySQL创建用户与授权方法 作者: 字体:[增加 减小] 类型:转载 时间:2012-11-10我要评论 MySQL中创建用户与授权的实现方法,对于刚开始接触mysql的朋友可以参考下 注:我的运行环境是widnows xp professional + MySQL5.0 一, 创建用户: 命令:CREATE USER 'username'@'host' IDENTIFIED BY 'password'; 说明:username - 你将创建的用户名, host - 指定该用户在哪个主机上可以

CentOS6.2 yum安装配置lnmp服务器(Nginx+PHP+MySQL)

1.配置防火墙,开启80端口.3306端口        vi /etc/sysconfig/iptables        -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT(允许80端口通过防火墙)        -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT(允许3306端口通过防火墙) 特别提示:很多网友把这两条规则添加到防火

CentOS 7 安装 MySQL

环境 CentOS 7.1 (64-bit system) MySQL 5.6.24 CentOS 安装 参考:http://www.waylau.com/centos-7-installation-and-configuration/ 转载自:http://www.centoscn.com/mysql/2016/0315/6844.html 依赖 MySQL 依赖 libaio,所以先要安装 libaio yum search libaio # 检索相关信息 yum install libai

MySQL查询今天/昨天/本周、上周、本月、上个月份数据的sql代码

MySQL查询本周.上周.本月.上个月份数据的sql代码 作者: 字体:[增加 减小] 类型:转载 时间:2012-11-29我要评论 MySQL查询的方式很多,下面为您介绍的MySQL查询实现的是查询本周.上周.本月.上个月份的数据,如果您对MySQL查询方面感兴趣的话,不妨一看 今天sql and TO_DAYS( now() ) - TO_DAYS(subscribeTime) = 0 昨天sql and TO_DAYS( now() ) - TO_DAYS(subscribeTime)

MySql模糊查询like通配符使用详细介绍

MySql模糊查询like通配符使用详细介绍 转载:http://chenpeng.info/html/2020 MySQL提供标准的SQL模式匹配,以及一种基于象Unix实用程序如vi.grep和sed的扩展正则表达式模式匹配的格式. 一.SQL模式 SQL的模式匹配允许你使用“_”匹配任何单个字符,而“%”匹配任意数目字符(包括零个字符).在 MySQL中,SQL的模式缺省是忽略大小写的.下面显示一些例子.注意在你使用SQL模式时,你不能使用=或!=:而使用LIKE或NOT LIKE比较操作

(002)MySQL程序、工具概述

十年运维系列之基础篇 - MySQL 作者:曾林 联系:[email protected] 网站:www.jplatformx.com 版权:文章未经同意请勿转载 一.引言 要特别注意mysql和mysqld的区别.mysql是mysqld数据库服务器进程的客户端连接程序,而mysqld指的是服务器.可以跟我们日常开发的web系统来做一个类别.mysql就相当于浏览器比如IE,而mysqld就相当于web服务器比如(Apache). MySQL AB是诞生MySQL数据库的公司.以下就介绍此公司

MySQL 导出一句话

听说是很老的东西了,学习的时候发现还是很好用的,故学习转载过来,留备学习. mysql 导出一句话 方法1:网上流行的方法 流程:(1)建表--->(2)插入数据--->(3)select查询导出 USE test; #调用test数据库:DROP TABLE IF EXISTS tmp; # 测试当前数据中是否存在tmp表:CREATE TABLE tmp(cmd TEXT NOT NULL); # 创建表tmp,且其中的字段为cmd,值不能为空:INSERT INTO tmp(cmd) V