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. ABAP CDS ON HANA-(11)ABAP CDSでの関連付け

    Association in ABAP CDS An association in CDS view joins different data sources. Defining and using ...

  2. Java:位移运算符

    Java中有三个位移运算符,用于对int类型整数的二进制补码进行操作: 1. "<<": 左移运算符 在二进制补码末尾添加“0”,之前的其他位相当于左移了一位,可看作成 ...

  3. Hibernate-ORM:08.Hibernate中的投影查询

    ------------吾亦无他,唯手熟尔,谦卑若愚,好学若饥------------- 本篇博客将叙述hibernate中的投影查询 一,目录: 1.解释什么是投影查询 2.返回Object单个对象 ...

  4. Android之线程安全的单例模式,Adapter注意事项之引用传值

    线程安全的单例模式单位模式一般写法如下: public static FestivalLab mInstance; private FestivalLab() { } public static Fe ...

  5. 「日常训练」「小专题·图论」 Frogger (1-1)

    题意 分析 变形的dijkstra. 分析题意之后补充. 代码 // Origin: // Theme: Graph Theory (Basic) // Date: 080518 // Author: ...

  6. Python request 简单使用

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  7. 分布式资源调度--YARN框架

    YARN产生背景 YARN是Hadoop2.x才有的,所以在介绍YARN之前,我们先看一下MapReduce1.x时所存在的问题: 单点故障 节点压力大 不易扩展 MapReduce1.x时的架构如下 ...

  8. C++中的默认参数规则

    C++中的默认参数规则 C++的默认参数规则其实是一个非常容易掉坑的规则,尤其是当一个函数拥有多个声明的时候,每个声明的默认参数可以各不相同,在调用时又可能与每个声明都不同:这篇博客稍微列举一下C++ ...

  9. 《Deep Learning》第二章 线性代数 笔记

    第二章 线性代数 2.1 名词 标量(scalar).向量(vector).矩阵(matrix).张量(tensor) 2.2 矩阵和向量相乘 1. 正常矩阵乘法: 2. 向量点积: 3. Hadam ...

  10. POJ 2135 Farm Tour(最小费用最大流)

    Description When FJ's friends visit him on the farm, he likes to show them around. His farm comprise ...