MySQL : interactive_timeout v/s wait_timeout

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,布布扣,bubuko.com

时间: 2024-10-13 03:53:39

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

Ubuntu下mysql修改连接超时wait_timeout

命令行登入mysql show variables like '%timeout%':(其中有用的是: interactive_timeout  和wait_timeout  为28800,默认为8小时设置:) set ? interactive_timeout=764000;  set  ?wait_timeout=764000; (设置为10天) 执行?show variables like '%timeout%':看看执行成功没有

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

1)interactive_timeout:参数含义:服务器关闭交互式连接前等待活动的秒数.交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端.参数默认值:28800秒(8小时) (2)wait_timeout:参数含义:服务器关闭非交互连接之前等待活动的秒数.在线程启动时,根据全局wait_timeout值或全局interactive_timeout值初始化会话wait_timeout值,取决于客户端类型(由mysql_real_

mysql数据库配置wait_timeout和interactive_timeout总结

(1)interactive_timeout:参数含义:服务器关闭交互式连接前等待活动的秒数.交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端.参数默认值:28800秒(8小时) (2)wait_timeout:参数含义:服务器关闭非交互连接之前等待活动的秒数.在线程启动时,根据全局wait_timeout值或全局interactive_timeout值初始化会话wait_timeout值,取决于客户端类型(由mysql_real

关于mysql的wait_timeout参数 设置不生效的问题【转】

关于wait_timeout 有一次去online set wait_timeout 的时候发现改了不生效,如下: mysql> show variables like 'wait_timeout';+---------------+-------+| Variable_name | Value |+---------------+-------+| wait_timeout | 100 |+---------------+-------+1 row in set (0.00 sec) mysq

interactive_timeout和wait_timeout的关系

interactive_timeout = 28800 wait_timeout = 28800 #这两个参数默认都是28800s,即8个小时; interactive_timeout指的是mysql在关闭一个交互的连接之前所要等待的秒数 wait_timeout指的是mysql在关闭一个非交互的连接之前所要等待的秒数 通过mysql客户端连接数据库是交互式连接,通过jdbc连接数据库是非交互式连接 (1)session级别修改interactive_timeout=10,wait_timeou

关于mysql的wait_timeout参数 设置不生效的问题

关于wait_timeout 有一次去online set wait_timeout 的时候发现改了不生效,如下: mysql> show variables like 'wait_timeout';+---------------+-------+| Variable_name | Value |+---------------+-------+| wait_timeout | 100 |+---------------+-------+1 row in set (0.00 sec) mysq

MySQL 死锁与日志二三事

最近线上 MySQL 接连发生了几起数据异常,都是在凌晨爆发,由于业务场景属于典型的数据仓库型应用,白天压力较小无法复现.甚至有些异常还比较诡异,最后 root cause 分析颇费周折.那实际业务当中咱们如何能快速的定位线上 MySQL 问题,修复异常呢?下文我会根据两个实际 case,分享下相关的经验与方法. 1.Case1:部分数据更新失败 某天渠道同学反馈某报表极个别渠道数据为 0,大部分渠道数据正常.这个数据是由一个统计程序每天凌晨例行更新的,按理来说,要么全部正常,要么全部失败,那会

mysql 执行show processlist出现很多大量的 ”unauthenticated user”的解决

今天测试人员反映,一台测试环境mysql服务器查询很慢,有时登录不上, 在top中发现cpu被大量占用,系统内存还有,jave程序运行的很慢,登录服务器, show full processlist 刷屏了很多进程,还有大量 unauthenticated user 状态的 连接如下:| 6465371 | unauthenticated user | connecting host      | NULL               | Connect |  NULL | login    

mysql配置文件my.cnf整理

随时修改: 1 [mysqld] 2 #basedir= 3 datadir=/var/lib/mysql 4 #mysql.default_port=3306 5 #mysql.default_socket=/tmp/mysql.sock 6 socket=/var/lib/mysql/mysql.sock 7 #socket=/tmp/mysql.sock 8 user=mysql 9 # Disabling symbolic-links is recommended to prevent