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.

asked Mar 3 '11 at 20:37
Patrick

1,46461625
 

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.

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

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

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

    原文地址:使用Anemometer基于pt-query-digest将MySQL慢查询可视化 作者:84223932 本文主要介绍使用Anemometer基于pt-query-digest将MySQL ...

  2. 转载---Beats:如何使用Filebeat将MySQL日志发送到Elasticsearch

    在今天的文章中,我们来详细地描述如果使用Filebeat把MySQL的日志信息传输到Elasticsearch中.为了说明问题的方便,我们的测试系统的配置是这样的: 我有一台MacOS机器.在上面我安 ...

  3. 转载:centos7下使用yum安装mysql

    转自:http://www.cnblogs.com/hwd-cnblogs/p/5213337.html CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql ...

  4. [转载] 运维角度浅谈:MySQL数据库优化

    一个成熟的数据库架构并不是一开始设计就具备高可用.高伸缩等特性的,它是随着用户量的增加,基础架构才逐渐完善. 作者:zhenliang8,本文转自51CTO博客,http://lizhenliang. ...

  5. 【转载】MyBatis JdbcType 与Oracle、MySql数据类型对应关系详解

    [原文链接]:MyBatis JdbcType 与Oracle.MySql数据类型对应关系详解 1. Mybatis JdbcType与Oracle.MySql数据类型对应列表 2. Mybatis ...

  6. mysql connections

    在使用MySQL数据库的时候,经常会遇到这么一个问题,就是“Can not connect to MySQL server. Too many connections”-mysql 1040错误,这是 ...

  7. (转载)Mysql查找如何判断字段是否包含某个字符串

    (转载)http://www.th7.cn/db/mysql/201306/31159.shtml 有这样一个需求,在Mysql数据库字符串字段(权限)中,用户有多个不同的邮箱,分别被‘,’分开,现在 ...

  8. (转载)mysql中百万级数据插入速度测试

    (转载)http://www.111cn.net/database/mysql/42453.htm 100W的数据对于很多朋友来说算小菜了,但今天我就想到创建一个大量数据的测试环境,于是找了一下怎么插 ...

  9. MYSQL 50 基础题 (转载)

    MYSQL 50 基础题 (转载) 前言:最近在强化MYSQL 能力 答案在(也是转载处) https://www.cnblogs.com/kangxinxin/p/11585935.html 下面是 ...

随机推荐

  1. HDU暑假多校第六场K-werewolf

    一.题意 好人必然说真话,坏人不一定说真话,给定N个人的言论<每人一个发言.不谈及自己>,要求指出有多少个人一定是好人,有多少个人一定是坏人.#define 狼人 坏人#define 村民 ...

  2. maven中settings文件的配置

    鉴于上一个博客写的maven打包,读者老爷们可能找不到settings文件的配置,这里专门附上settings文件的配置: 有的settings文件只含有一些空标签,需要手动去配置. <?xml ...

  3. C# 控制台应用程序输出颜色字体

    最佳解决方案的代码: static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Green; Console.W ...

  4. HTC Vive小场地与大场景空间的解决方案

    本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/52780621 作者:car ...

  5. 不同编译器下,定义一个地址按x字节对齐的数组

    以前一直用MDK,用__align(4)就可以定义一个首地址被4整除.地址按4字节对齐的数组,但今天用IAR发现这么写编译报错. 搜了一下才发现,原来不同的编译器,需要用不同的表达方式: #if de ...

  6. 创龙TMS320C6748开发找不到 tl.dsp.evm6748的问题研究

    1. 使用中遇到问题,看了一下帖子说是把tl.dsp.evm6748换成ti.platforms.evm6748可以编译过去.这个包是在XDCtools里面的. js: "D:/ti/ccs ...

  7. VI的配置

    vi下设置tab键为4个空格 在每个用户的主目录下,都有一个 vi 的配置文件".vimrc"或".exrc",没有的可以新建一个.用户可以编辑它,使这些设置在 ...

  8. EF报错“EntityValidationErrors”

          在使用EF更新实体的时候报错,显示界面如下:       点击查看详情:        在查看详细的窗体中,EntityValidationErrors里面的也看不到具体的错误原因.在网上 ...

  9. 孤荷凌寒自学python第七十五天开始写Python的第一个爬虫5

    孤荷凌寒自学python第七十五天开始写Python的第一个爬虫5 (完整学习过程屏幕记录视频地址在文末) 今天在上一天的基础上继续完成对我的第一个代码程序的书写. 直接上代码.详细过程见文末屏幕录像 ...

  10. winform showDialog() 退出问题

    今日发现: 当返回值为Dialog.OK时,会自动退出,不需要this.close().别的返回值仍需要.