Most of the database intensive applications are worring about the default values of these variables obviously. Developers used to inform me that they need to extend the wait_timeout value in order to complete the query execution.

After some googling, it is found that default “wait_timeout” value is good enough. We may need to reduce it to boost the server performance which will helpful to minimize the “sleep” process loaded in memory. Increasing number of sleeping process will reduces the server performance gradually. So always keep the default value and make it reduce until the program/application does not create any sleeping process which would helpful to improve the performance noticeable. Slow_log_query is another possible reason to have many sleeping process.

interactive_timeout : interactive time out for mysql shell sessions in seconds like mysqldump or mysql command line tools.
wait_timeout” : the amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection in seconds.

How to change the these variables

a. changing values at run time 
Log in to the mysql console and set the variable.

mysql> SET  interactive_timeout=200;
Query OK, 0 rows affected (0.01 sec) mysql> SET GLOBAL interactive_timeout=200;
Query OK, 0 rows affected (0.00 sec) mysql> show variables like "%timeout%";
+----------------------------+-------+
| Variable_name | Value |
+----------------------------+-------+
| connect_timeout | 200 |
| delayed_insert_timeout | 300 |
| innodb_lock_wait_timeout | 50 |
| innodb_rollback_on_timeout | OFF |
| interactive_timeout | 200 |
| net_read_timeout | 200 |
| net_write_timeout | 200 |
| slave_net_timeout | 3600 |
| table_lock_wait_timeout | 50 |
| wait_timeout | 200 |
+----------------------------+-------+
10 rows in set (0.00 sec)

b. Using my.cnf : Add the following values in /etc/my.cnf” and restart the mysql server.

 [mysqld]
interactive_timeout=180
wait_timeout=180

Pls note that “wait_timeout” would be helpful to clear the sleeping process as “interactive_timeout” does not make any performance improvement since it affect the command line sessions. Obviously increasing the values of connect_timeoutnet_read_timeout andnet_write_timeout would help to skip the timeout errors when lengthy queries are being executed.

How to kill the MySQL Sleeping process

mysql> show full processlist;
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| 9435 | user | 192.168.10.15:52180 | db1 | Sleep | 26 | | NULL |
| 9943 | user | localhost:51179 | db2 | Sleep | 1 | | NULL |
| 9944 | user | localhost:54007 | db2 | Sleep | 29 | | NULL |
| 9947 | user | localhost:60638 | db2 | Sleep | 29 | | NULL |
| 10716 | root | localhost | NULL | Sleep | 5432 | | NULL |
| 10851 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
6 rows in set (0.00 sec) mysql> kill 9944;
Query OK, 0 rows affected (0.00 sec) mysql> show full processlist;
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
| 9435 | user | 192.168.10.15:52180 | db1 | Sleep | 7 | | NULL |
| 9943 | user | localhost:51179 | db2 | Sleep | 9 | | NULL |
| 9947 | user | localhost:60638 | db2 | Sleep | 10 | | NULL |
| 10716 | root | localhost | NULL | Sleep | 5473 | | NULL |
| 10851 | root | localhost | NULL | Query | 0 | NULL | show full processlist |
| +-------+------------+---------------------+---------------+---------+------+-------+-----------------------+
7 rows in set (0.01 sec)
mysql>

On thread startup, the session wait_timeout value is initialized from the global wait_timeout value or from the global interactive_timeout value, depending on the type of client (as defined by the CLIENT_INTERACTIVEconnect option to mysql_real_connect()).

参考:

http://www.serveridol.com/2012/04/13/mysql-interactive_timeout-vs-wait_timeout/

http://dev.mysql.com/doc/refman/5.5/en/server-system-variables.html#sysvar_wait_timeout

MySQL : interactive_timeout v/s wait_timeout的更多相关文章

  1. Ubuntu下mysql修改连接超时wait_timeout

    命令行登入mysql show variables like '%timeout%':(其中有用的是: interactive_timeout  和wait_timeout  为28800,默认为8小 ...

  2. Could not open Hibernate Session for transaction; nested exception is org.hibernate.TransactionExcep linux下mysql修改连接超时wait_timeout修改后就ok了

    Linux下mysql修改连接超时wait_timeout 1,首先: show variables like '%timeout%': 显示结果: +------------------------ ...

  3. MySQL配置参数:wait_timeout

    作者:老王 如果你没有修改过MySQL的配置,缺省情况下,wait_timeout 的初始值是. wait_timeout过大有弊端,其体现就是MySQL里大量的SLEEP进程无法及时释放,拖累系统性 ...

  4. MySQL查看和修改wait_timeout

    1.全局查看wait_timeout值 mysql> show global variables like 'wait_timeout'; 2.修改全局wait_timeout值 set glo ...

  5. MySQL中的配置参数interactive_timeout和wait_timeout(可能导致过多sleep进程的两个参数)

    1)interactive_timeout:参数含义:服务器关闭交互式连接前等待活动的秒数.交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的 ...

  6. 设置mysql的interactive_timeout和wait_timeout的值

    1,为什么要重新设置这两个变量的值? 因为如果数据库默认这两个变量的值是8小时(即28800秒)如果在8小时之内没有连接到数据库,等下次再连的时候就会抛连接超时,或连接关闭这样的异 常,但是多连接几次 ...

  7. mysql wait_timeout和interactive_timeout总结

      (1)interactive_timeout:参数含义:服务器关闭交互式连接前等待活动的秒数.交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE ...

  8. MySQL:参数wait_timeout和interactive_timeout以及空闲超时的实现【转】

    一.参数意思 这里简单解释一下两个参数,含义如下: interactive_timeout:The number of seconds the server waits for activity on ...

  9. interactive_timeout和wait_timeout(

    mysql> show variables like "%timeout%"; +-----------------------------+----------+ | Va ...

随机推荐

  1. UIlabel设置不同的颜色

    NSString *string = @"注册过程中出现问题,致电400-650-5167联系会养车工作人员";    NSRange range = [string rangeO ...

  2. ubuntu下openoffice开发环境配置

    安装openoffice或者liboffice 路径:/usr/lib/openoffice/program ,soffice 开启服务: 安装JDK 其默认路径:jdk7 版本号:1.7...,jd ...

  3. hdu 2085

    PS:递推题..  a[n]=a[n-1]*3+2*b[n-1]  b[n]=a[n-1]+b[n-1] 代码: #include "stdio.h" ]; ]; int main ...

  4. 2016 - 1 - 3 国旗选择demo

    // // ViewController.m // 国旗 // // Created by Mac on 16/1/3. // Copyright © 2016年 Mac. All rights re ...

  5. linux下的文件权限管理

    权限管理有两个层面 第一层区分用户:文件属主(u), 组用户(g), 其它(o) 第二层区分权限:读(r),写(w),可执行(x) 这两个层次构成文件权限管理的二维结构 u         g     ...

  6. 显示ios设备信息的程序

    以下是运行在本人iphone4上的截图,支持中文简体,中文繁体,英文,支持iphone和ipad,当然由于没有ipad,ipad的测试用的模拟器.支持iphone4的Retina屏幕.本来有6个标签, ...

  7. Ubuntu安装软件提示”需要安装不能信任的软件包”解决办法

    用 Ubuntu 安装输入法软件包时提示"需要安装不能信任的软件包","这个动作需要从没有授权的软件源来安装软件包",赋予权限执行仍然无法安装,上网查了一下,只 ...

  8. iOS APP上线流程

    前言:作为一名IOS开发者,把开发出来的App上传到App Store是必须的.下面就来详细介绍下具体流程. 1.打开苹果开发者中心:https://developer.apple.com 打开后点击 ...

  9. IOS 作业项目(2) 画图(保存,撤销,笔粗细设定功能)

    先上效果图

  10. SQL技巧

    数据查询    且不说你是否正在从事编程方面的工作或者不打算学习SQL,可事实上几乎每一位开发者最终都会遭遇它.你多半还用不着负责创建和维持某个数据库,但你怎么着也该知道以下的一些有关的SQL知识.我 ...