转载

【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?

【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?






 

真题1、参数wait_timeoutinteractive_timeout的作用和区别是什么?

答案:interactive_timeout表示MySQL服务器关闭交互式连接前等待活动的秒数;wait_timeout表示MySQL服务器关闭非交互连接之前等待活动的秒数。这2个参数的默认值都是28800,单位秒,即8个小时。需要注意的是,这2个参数需要同时设置才会生效。

参数interactive_timeout针对交互式连接,wait_timeout针对非交互式连接。所谓的交互式连接,即在mysql_real_connect()函数中使用了CLIENT_INTERACTIVE选项。说得直白一点就是,通过MySQL客户端连接数据库是交互式连接,通过jdbc连接数据库是非交互式连接。其实,针对Client,真正生效的是会话级别的wait_timeout,空闲连接(交互和非交互)超过其会话级别的wait_timeout时间就会被回收掉。在客户端连接启动的时候,根据连接的类型,来确认会话变量wait_timeout的值是继承于全局变量wait_timeout,还是interactive_timeout。对于非交互式连接,类似于jdbc连接,wait_timeout的值继承自服务器端全局变量wait_timeout。对于交互式连接,类似于MySQL客户单连接,wait_timeout的值继承自服务器端全局变量interactive_timeout

可通过查看show processlist输出中Sleep状态的时间来判断一个连接的空闲时间。若超过wait_timeout的值,则会报类似于如下的错误:

mysql> set session WAIT_TIMEOUT=3;

Query OK, 0 rows affected (0.00 sec)

 

mysql> show processlist;

ERROR 2013 (HY000): Lost connection to MySQL server during query

mysql>

mysql> show processlist;

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect...

Connection id:    50

Current database: lhrdb

 

+----+------+-------------+-------+---------+------+----------+------------------+

| Id | User | Host        | db    | Command | Time | State    | Info             |

+----+------+-------------+-------+---------+------+----------+------------------+

|  7 | root | localhost   | NULL  | Sleep   | 7131 |          | NULL             |

| 26 | root | localhost   | NULL  | Sleep   | 7071 |          | NULL             |

| 27 | root | localhost   | NULL  | Sleep   | 7064 |          | NULL             |

| 28 | root | LHRDB:47234 | NULL  | Sleep   | 6803 |          | NULL             |

| 50 | root | LHRDB:47238 | lhrdb | Query   |    0 | starting | show processlist |

+----+------+-------------+-------+---------+------+----------+------------------+

5 rows in set (0.02 sec)

 

& 说明:

有关参数wait_timeoutinteractive_timeout的更多内容可以参考我的博客:http://blog.itpub.net/26736162/viewspace-2149454/

 

 









MySQL中interactive_timeout和wait_timeout的区别

在用mysql客户端对数据库进行操作时,打开终端窗口,如果一段时间没有操作,再次操作时,常常会报如下错误:

ERROR 2013 (HY000): Lost connection to MySQL server during query
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...

 

这个报错信息就意味着当前的连接已经断开,需要重新建立连接。

 

那么,连接的时长是如何确认的?

其实,这个与interactive_timeout和wait_timeout的设置有关。

 

首先,看看官方文档对于这两个参数的定义

interactive_timeout

默认是28800,单位秒,即8个小时

The number of seconds the server waits for activity on an interactive connection before closing it. An interactive client is defined as a client that uses the CLIENT_INTERACTIVE option to mysql_real_connect(). See also wait_timeout.

 

wait_timeout

默认同样是28800s

The number of seconds the server waits for activity on a noninteractive connection before closing it.

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_INTERACTIVE connect option to mysql_real_connect()). See also interactive_timeout.

 

根据上述定义,两者的区别显而易见

1> interactive_timeout针对交互式连接,wait_timeout针对非交互式连接。所谓的交互式连接,即在mysql_real_connect()函数中使用了CLIENT_INTERACTIVE选项。

     说得直白一点,通过mysql客户端连接数据库是交互式连接,通过jdbc连接数据库是非交互式连接。 

2> 在连接启动的时候,根据连接的类型,来确认会话变量wait_timeout的值是继承于全局变量wait_timeout,还是interactive_timeout。

 

下面来测试一下,确认如下问题

1. 控制连接最大空闲时长的是哪个参数。

2. 会话变量wait_timeout的继承问题

 

Q1:控制连接最大空闲时长的是哪个参数

A1:wait_timeout

验证

只修改wait_timeout参数

mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 28800          |
| WAIT_TIMEOUT        | 28800          |
+---------------------+----------------+
rows in set (0.03 sec)


mysql> set session WAIT_TIMEOUT=10;
Query OK, 0 rows affected (0.00 sec)
-------等待10s后再执行
mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
ERROR 2013 (HY000): Lost connection to MySQL server during query

可以看到,等待10s后再执行操作,连接已经断开。

 

只修改interactive_timeout参数

mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 28800          |
| WAIT_TIMEOUT        | 28800          |
+---------------------+----------------+
rows in set (0.06 sec)


mysql> set session INTERACTIVE_TIMEOUT=10;
Query OK, 0 rows affected (0.00 sec)
----------等待10s后执行
mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 10             |
| WAIT_TIMEOUT        | 28800          |
+---------------------+----------------+
rows in set (0.06 sec)

 

Q2:会话变量wait_timeout的继承问题

A2:如果是交互式连接,则继承全局变量interactive_timeout的值,如果是非交互式连接,则继承全局变量wait_timeout的值。

验证:

只修改全局变量interactive_timeout的值

mysql> select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout'); 
+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 28800          |
| WAIT_TIMEOUT        | 28800          |
+---------------------+----------------+
rows in set (0.13 sec)


mysql> set global INTERACTIVE_TIMEOUT=10;
Query OK, 0 rows affected (0.00 sec)


mysql> select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout');
+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 10             |
| WAIT_TIMEOUT        | 28800          |
+---------------------+----------------+
rows in set (0.00 sec)

 

开启另外一个mysql客户端,查看会话变量的值

mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 10             |
| WAIT_TIMEOUT        | 10             |
+---------------------+----------------+
rows in set (0.00 sec)

发现,WAIT_TIMEOUT的值已经变为10了。

 

但通过jdbc测试,wait_timeout的值依旧是28800

【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
public class Jdbc_test {
    @SuppressWarnings("static-access") public static void main(String[] args) throws Exception {
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         String url = "jdbc:mysql://192.168.244.10:3306/test";
         String user = "root";
         String password = "123456";
         Class.forName("com.mysql.jdbc.Driver");
         conn = DriverManager.getConnection(url, user, password);
         stmt = conn.createStatement();
         String sql = "select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout')";
         rs = stmt.executeQuery(sql); while (rs.next()) {
             System.out
                     .println(rs.getString(1)+":  "+rs.getString(2));
         } }
}
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?

结果输出如下:

INTERACTIVE_TIMEOUT:  10 
WAIT_TIMEOUT: 28800

 

 只修改全局变量wait_timeout的值

mysql> select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wa
it_timeout');+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 28800          |
| WAIT_TIMEOUT        | 28800          |
+---------------------+----------------+
rows in set (0.17 sec)


mysql> set global WAIT_TIMEOUT=20;
Query OK, 0 rows affected (0.07 sec)


mysql> select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wa
it_timeout');+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 28800          |
| WAIT_TIMEOUT        | 20             |
+---------------------+----------------+
rows in set (0.00 sec)

 

开启另外一个mysql客户端,查看会话变量的值

mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
+---------------------+----------------+
| variable_name       | variable_value |
+---------------------+----------------+
| INTERACTIVE_TIMEOUT | 28800          |
| WAIT_TIMEOUT        | 28800          |
+---------------------+----------------+
rows in set (0.03 sec)

WAIT_TIMEOUT的值依旧是28800.

 

查看jdbc的结果

【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
public class Jdbc_test {
    @SuppressWarnings("static-access") public static void main(String[] args) throws Exception {
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         String url = "jdbc:mysql://192.168.244.10:3306/test";
         String user = "root";
         String password = "123456";
         Class.forName("com.mysql.jdbc.Driver");
         conn = DriverManager.getConnection(url, user, password);
         stmt = conn.createStatement();
         String sql = "select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout')";
         rs = stmt.executeQuery(sql); while (rs.next()) {
             System.out
                     .println(rs.getString(1)+":  "+rs.getString(2));
         }
         Thread.currentThread().sleep(21000);
         sql = "select 1 from dual";
         rs = stmt.executeQuery(sql); while (rs.next()) {
             System.out
                     .println(rs.getInt(1));
         }

    }
}
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?

查看jdbc的结果

INTERACTIVE_TIMEOUT:  28800 WAIT_TIMEOUT: 20

同时,新增了一段程序,等待20s后,再次执行查询,报如下错误:

【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
Exception in thread "main" com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Last packet sent to the server was 12 ms ago.
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
    at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3009)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2895)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3438)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1951)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2101)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2548)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2477)
    at com.mysql.jdbc.StatementImpl.executeQuery(StatementImpl.java:1422)
    at com.victor_01.Jdbc_test.main(Jdbc_test.java:29)
Caused by: java.net.SocketException: Software caused connection abort: recv failed
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.socketRead(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SocketInputStream.read(Unknown Source)
    at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
    at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
    at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
    at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2452)
    at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2906)
    ... 8 more
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?

 

总结

1. 控制连接最大空闲时长的wait_timeout参数。

2. 对于非交互式连接,类似于jdbc连接,wait_timeout的值继承自服务器端全局变量wait_timeout。

    对于交互式连接,类似于mysql客户单连接,wait_timeout的值继承自服务器端全局变量interactive_timeout。

3. 判断一个连接的空闲时间,可通过show processlist输出中Sleep状态的时间

mysql> show processlist;
+----+------+----------------------+------+---------+------+-------+------------------+
| Id | User | Host                 | db   | Command | Time | State | Info             |
+----+------+----------------------+------+---------+------+-------+------------------+
|  2 | root | localhost            | NULL | Query   |    0 | init  | show processlist |
|  6 | repl | 192.168.244.20:44641 | NULL | Sleep   | 1154 |       | NULL             |
+----+------+----------------------+------+---------+------+-------+------------------+
rows in set (0.03 sec)

 

参考

1. http://www.cnblogs.com/cenalulu/archive/2012/06/20/2554863.html

2. http://www.cnblogs.com/Alight/p/4118515.html

3. http://ronaldbradford.com/blog/sqlstatehy000-general-error-2006-mysql-server-has-gone-away-2013-01-02/



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_connect()的连接选项CLIENT_INTERACTIVE定义)。
参数默认值:28800秒(8小时)

MySQL服务器所支持的最大连接数是有上限的,因为每个连接的建立都会消耗内存,因此我们希望客户端在连接到MySQL Server处理完相应的操作后,应该断开连接并释放占用的内存。如果你的MySQL Server有大量的闲置连接,他们不仅会白白消耗内存,而且如果连接一直在累加而不断开,最终肯定会达到MySQL Server的连接上限数,这会报'too many connections'的错误。对于wait_timeout的值设定,应该根据系统的运行情况来判断。在系统运行一段时间后,可以通过show processlist命令查看当前系统的连接状态,如果发现有大量的sleep状态的连接进程,则说明该参数设置的过大,可以进行适当的调整小些。

问题:
   如果在配置文件my.cnf中只设置参数wait_timeout=100,则重启服务器后进入,执行:
   Mysql> show variables like “%timeout%”;
会发现参数设置并未生效,仍然为28800(即默认的8个小时)。
查询资料后,要同时设置interactive_timeout和wait_timeout才会生效。
【mysqld】
wait_timeout=100
interactive_timeout=100
重启MySQL Server进入后,查看设置已经生效。


问题1:这里为什么要同时设置interactive_timeout,wait_timeout的设置才会生效?

问题2:interactive的值如果设置的和wait_timeout不同,为什么Interactive_timeout会覆盖wait_timeout?

问题3:在进行MySQL优化时,因为interactive_timeout决定的是交互连接的时间长短,而wait_timeout决定的是非交互连接的时间长短。如果在进行连接配置时mysql_real_connect()最后一个参数client_flag不设置为CLIENT_INTERACTIVE,是不是interactive_timeout的值不会覆盖wait_timeout?

问题4:为了减少长连接的数量,在设置优化时是不是可以将interactive_timeout的值设置的大些,而wait_timeout的值设置的小些?但是问题2的描述好像又不允许这样。。。




关于MySQL的interactive_timeout和wait_timeout

[日期:2017-08-18] 来源:Linux社区  作者:杨奇龙 [字体:  ]

一 前言
  这篇文章源于自己一个无知的提问,作为一个DBA 老鸟,实在汗颜 。如图,修改wait_timeout参数之后 并没有及时生效,于是乎去跑到技术支持群里问了。。ps 应该去查g.cn 才对。。
 【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
  本文通过测试我们要弄清楚两个问题
  a 继承关系 wait_timeout在session和global级别分别继承那个参数?
  b 生效参数 在会话中到底哪个参数决定了会话的存活时间?

二 参数介绍  
首先说明两个关键词 通过MySQL 客户端连接db的是交互会话,通过jdbc等程序连接db的是非交互会话
interactive_timeout: MySQL服务器关闭交互式连接前等待的秒数。交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端。参数默认值:28800秒(8小时)
wait_timeout:          MySQL服务器关闭非交互连接之前等待的秒数。在会话启动时,根据全局wait_timeout值或全局interactive_timeout值初始化会话wait_timeout值,取决于客户端类型--由mysql_real_connect()的连接选项CLIENT_INTERACTIVE定义。参数默认值:28800秒(8小时)
2.1 继承关系 
1) 单独设置global级别的interactive_timeout  

  1. set global interactive_timeout = 300 
  2. session1 [RO] 09:34:20 >set global interactive_timeout=300;
  3. Query OK, 0 rows affected (0.00 sec)
  4. session1 [RO] 09:39:15 >select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout');
  5. +---------------------+----------------+
  6. | variable_name       | variable_value |
  7. +---------------------+----------------+
  8. | INTERACTIVE_TIMEOUT | 300            |
  9. | WAIT_TIMEOUT        | 28800          |
  10. +---------------------+----------------+
  11. 2 rows in set (0.00 sec)
  12. session1 [RO] 09:39:21 >select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
  13. +---------------------+----------------+
  14. | variable_name       | variable_value |
  15. +---------------------+----------------+
  16. | INTERACTIVE_TIMEOUT | 300            |
  17. | WAIT_TIMEOUT        | 28800          |
  18. +---------------------+----------------+
  19. 2 rows in set (0.00 sec)
  20. 登陆另外一个会话
  21. session2 [RO] 09:39:35 >select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout');
  22. +---------------------+----------------+
  23. | variable_name       | variable_value |
  24. +---------------------+----------------+
  25. | INTERACTIVE_TIMEOUT | 300            |
  26. | WAIT_TIMEOUT        | 28800          |
  27. +---------------------+----------------+
  28. 2 rows in set (0.00 sec)
  29. session2 [RO] 09:39:51 >select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
  30. +---------------------+----------------+
  31. | variable_name       | variable_value |
  32. +---------------------+----------------+
  33. | INTERACTIVE_TIMEOUT | 300            |
  34. | WAIT_TIMEOUT        | 300            |
  35. +---------------------+----------------+
  36. 2 rows in set (0.00 sec)

分析
  在交互模式下,session和global级别的 interactive_timeout 继承了 interactive_timeout global的值。而 wait_timeout 的值,session级别继承了interactive_timeout。global级别的wait_timeout 则不受影响 。
2) 设置session级别的 interactive_timeout 

  1. session1 [RO] 09:44:07 >set session interactive_timeout=300;
  2. Query OK, 0 rows affected (0.00 sec)
  3. session1 [RO] 09:44:27 >select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout');
  4. +---------------------+----------------+
  5. | variable_name       | variable_value |
  6. +---------------------+----------------+
  7. | INTERACTIVE_TIMEOUT | 28800          |
  8. | WAIT_TIMEOUT        | 28800          |
  9. +---------------------+----------------+
  10. 2 rows in set (0.00 sec)
  11. session1 [RO] 09:44:31 >select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
  12. +---------------------+----------------+
  13. | variable_name       | variable_value |
  14. +---------------------+----------------+
  15. | INTERACTIVE_TIMEOUT | 300            |
  16. | WAIT_TIMEOUT        | 28800          |
  17. +---------------------+----------------+
  18. 2 rows in set (0.00 sec)
  19. 另外开启一个会话
  20. session2 [RO] 09:44:41 >select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
  21. +---------------------+----------------+
  22. | variable_name | variable_value |
  23. +---------------------+----------------+
  24. | INTERACTIVE_TIMEOUT | 28800 |
  25. | WAIT_TIMEOUT | 28800 |
  26. +---------------------+----------------+
  27. 2 rows in set (0.01 sec)
  28. session2 [RO] 09:44:44 >select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout');
  29. +---------------------+----------------+
  30. | variable_name       | variable_value |
  31. +---------------------+----------------+
  32. | INTERACTIVE_TIMEOUT | 28800          |
  33. | WAIT_TIMEOUT        | 28800          |
  34. +---------------------+----------------+
  35. 2 rows in set (0.00 sec)

分析
  从上面的例子来看 wait_timeout 并不受session级别的interactive_timeout的值的影响。  
3) 同时设置两者的值,且不同。

  1. session1 [RO] 09:46:42 >
  2. (none) [RO] 09:46:42 >set global interactive_timeout=300;
  3. Query OK, 0 rows affected (0.00 sec)
  4. session1 [RO] 09:46:55 >set global wait_timeout=360;
  5. Query OK, 0 rows affected (0.00 sec)
  6. 另开启一个会话
  7. session2 [RO] 09:47:20 >select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
  8. +---------------------+----------------+
  9. | variable_name       | variable_value |
  10. +---------------------+----------------+
  11. | INTERACTIVE_TIMEOUT | 300            |
  12. | WAIT_TIMEOUT        | 300            |
  13. +---------------------+----------------+
  14. 2 rows in set (0.00 sec)
  15. session2 [RO] 09:47:22 >select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout');
  16. +---------------------+----------------+
  17. | variable_name       | variable_value |
  18. +---------------------+----------------+
  19. | INTERACTIVE_TIMEOUT | 300            |
  20. | WAIT_TIMEOUT        | 360            |
  21. +---------------------+----------------+
  22. 2 rows in set (0.00 sec)

分析
 从案例1 2中可以得出session级别的wait_timeout 继承global 级别的 interactive_timeout 的值 global级别的session则不受影响。在没有改变 interactive_timeout的值的情况下,去修改wait_timeout的值
 结果无效。就会出现前言中我遇到的情况。
2.2 有效参数
  通过一个例子检测影响会话的参数是哪个?验证方式通过设置全局的timeout时间(注意两者时间不同),另外起一个会话

  1. session1 [RO] 10:20:56 >set global interactive_timeout=20;
  2. Query OK, 0 rows affected (0.00 sec)
  3. session1 [RO] 10:23:32 >set global wait_timeout=10;
  4. Query OK, 0 rows affected (0.00 sec)

会话2进行查询

  1. mysql> select sleep(5);
  2. +----------+
  3. | sleep(5) |
  4. +----------+
  5. | 0        |
  6. +----------+
  7. 1 row in set (5.01 sec)

然后在session1 中 查看show processlist;
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
分析
    交互式 timeout时间受global级别的interactive_timeout影响。
2)非交互模式
  目前的测试并没有达到预期,测试模型如下设置

  1. mysql> select variable_name,variable_value from information_schema.session_variables where variable_name in ('interactive_timeout','wait_timeout');
  2.   +---------------------+----------------+
  3.   | variable_name       | variable_value |
  4.   +---------------------+----------------+
  5.   | INTERACTIVE_TIMEOUT | 35             |
  6.   | WAIT_TIMEOUT        | 35             |
  7.   +---------------------+----------------+
  8.   2 rows in set (0.00 sec)
  9.   mysql> select variable_name,variable_value from information_schema.global_variables where variable_name in ('interactive_timeout','wait_timeout');
  10.   +---------------------+----------------+
  11.   | variable_name       | variable_value |
  12.   +---------------------+----------------+
  13.   | INTERACTIVE_TIMEOUT | 35             |
  14.   | WAIT_TIMEOUT        | 25             |
  15.   +---------------------+----------------+
  16.   2 rows in set (0.00 sec)

在python命令行中模拟非交互数据来访问数据库,查看数据库timeout参数。同时在数据库中执行show processlist 查看python的连接多久会被关闭。
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
查看session级别的参数
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
查看show processlist,通过python程序连接数据库的会话等待了25s之后,被中断。
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
分析
1 通过python 命令行获取的timeout 参数和交互方式获取的并不一致,在交互命令行中获取session级别的wait_timeout 的值为35,使用非交互命令获取的值为25,说明wait_timeout继承全局的wait_timeout。
2 交互模式下会话空闲时间超过wait_timeout立即会被断开。

3) 思考题
  session1 通过非交互命令连接到db,此时全局的wait_timeout的值是28800,session 2 修改全局的wait_timeout 为30s ,问题 session1的会话会受到影响吗?

三 总结
 1 timeout 只是针对空闲会话有影响。
 2 session级别的wait_timeout继承global级别的interactive_timeout的值。而global级别的session则不受interactive_timeout的影响。
 3 交互式会话的timeout时间受global级别的interactive_timeout影响。因此要修改非交互模式下的timeout,必须同时修改interactive_timeout的值。
 4 非交互模式下,wait_timeout参数继承global级别的wait_timeout。

四 参考资料 
注意 本文测试的和参考资料并不完全相符,需要各位读者亲自测试,得到自己的结论。
[1]MySQL timeout相关参数解析和测试 
[2]MySQL中interactive_timeout和wait_timeout的区别 
[3]官方文档



 mysql的wait_timeout和interactive_timeout 2015-06-30 18:07:30

分类: MySQL


###wait_timeout interactive_timeout####

wait_timeout :对于非交互连接,mysql在关闭它之前的等待时间
              这个值的初始化根据连接客户端的连接方式不同:有两种方式:全局的wait_timeout或者是全局的interactive_timeout

interactive_timeout:对于交互连接,mysql在关闭它之前的等待时间

测试:
root:3406:(none)>show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 21       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

root:3406:(none)>show global variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 14       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

root:3406:(none)>show global variables like '%timeout%';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    4
Current database: *** NONE ***

+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 14       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

上面是测试交互输入的方式,
wait_timeout =14
interactive_timeout=21
可以看到session级别的wait_timeout的初始化使用了interactive_timeout
当超过了21s后,再执行命令连接已经被干掉了


综上:
针对client其实真正生效的是session级别的wait_timeout,空闲连接(交互和非交互),
超过其session级别的wait_timeout时间就会被回收掉:
伪代码:
if (client_connection is interactive) then
  session  wait_timeout= global interactive_timeout
else if(client_connection is noninteractive ) then
   session  wait_timeout= global wait_timeout
end if



[MySQL分享]--interactive_timeout和wait_timeout小结(interactive_timeout会覆盖wait_timeout)

原创 2015年09月21日 16:50:23
  • 标签:
  • mysql /
  • interactive_timeout /
  • wait_timeout
  • 1836

版权声明:声明:本文档可以转载,须署名原作者。 作者:无为 qq:490073687 周祥兴 zhou.xiangxing210@163.com


[plain] view plain copy
  1. # Connection timeout variables  
  2. #interactive_timeout:  
  3. #参数含义:服务器关闭交互式连接前等待活动的秒数。交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端。  
  4. #参数默认值:28800秒(8小时)  
  5. #wait_timeout:  
  6. #参数含义:服务器关闭非交互连接之前等待活动的秒数。  
  7. #在线程启动时,根据全局wait_timeout值或全局interactive_timeout值初始化会话wait_timeout值,  
  8. #取决于客户端类型(由mysql_real_connect()的连接选项CLIENT_INTERACTIVE定义)。  
  9. #参数默认值:28800秒(8小时)  
  10. 继续深入这两个变量wait_timeout的取值范围是1-2147483(Windows),1-31536000(linux)。  
  11.   
  12. 验证问题如下:  
  13. 1.修改my.cnf文件,分别设置wait_timeout和interactive_timeout不同的值,最终看谁覆盖谁?  
  14. 2.interactive_timeout对wait_timeout的影响。  
  15. 2.1 session.interactive_timeout<cnf.wait_timeout时,session.interactive_timeout是否会覆盖wait_timeout?  
  16. 2.2 session.interactive_timeout>cnf.wait_timeout时,session.interactive_timeout是否会覆盖wait_timeout?  
  17. 2.3 global.interactive_timeout<cnf.wait_timeout时,global.interactive_timeout是否会覆盖wait_timeout?  
  18. 2.4 global.interactive_timeout>cnf.wait_timeout时,global.interactive_timeout是否会覆盖wait_timeout?  
  19.   
  20. 3.wait_timeout对interactive_timeout的影响。  
  21. 3.1 session.wait_timeout<cnf.interactive_timeout时,session.wait_timeout是否会覆盖interactive_timeout?  
  22. 3.2 session.wait_timeout>cnf.interactive_timeout时,session.wait_timeout是否会覆盖interactive_timeout?  
  23. 3.3 global.wait_timeout<cnf.interactive_timeout时,global.wait_timeout是否会覆盖interactive_timeout?  
  24. 3.4 global.wait_timeout>cnf.interactive_timeout时,global.wait_timeout是否会覆盖interactive_timeout?  
  25.   
  26.   
  27. 4.什么要同时设置wait_timeout和interactive_timeout?  
  28. 5.set global wait_timeout=13;是否会影响到已经创建的会话? 不会  



先贴一下小结,后面实验有点长。


[plain] view plain copy
  1. 4.什么要同时设置wait_timeout和interactive_timeout?  
  2. 对于应用来说,  
  3. 如果用的是连接池,并且没有F5(F5可能会设置一个超时,把连接时间过长的session kill掉),那么两个timeout时间尽量设置长一些,避免应用连接池不断的重新连接数据库。  
  4. 如果你是短连接,那么就需要把两个timeout时间设置得短一些,否则数据库的最大连接数是有限的,很多连接一直不释放掉的话,浪费数据库资源,同时可能会有”MySQL: ERROR 1040: Too many connections”错误。  
  5.   
  6. 小结:  
  7.   a.在2.1和2.2两个试验中,修改会话级的session.interactive_timeout,对当前会话的超时时间wait_timeout没有影响。超时时间还是global.wait_timeout=cnf.interactive_timeout。  
  8.   b.在2.3和2.4两个实验中,修改全局级的global.interactive_timeout,对当前会话的超时时间wait_timeout不会马上有影响。  
  9.     当当前会话超时之后,才会生效(相当于新会话了)。对于新创建的会议由影响,而且全局级的interactive_timeout修改会覆盖新会话的wait_timeout。  
  10.   c.在3.1和3.2两个实验中,修改session.wait_timeout,   
  11.   如果session.wait_timeout<global.interactive_timeout时,起作用的超时时间是global.interactive_timeout。  
  12.   如果session.wait_timeout>global.interactive_timeout时,起作用的超时时间是session.wait_timeout。  
  13.   d.在3.3和3.4两个实验中,修改global.wait_timeout,不管值如何修改,起作用的超时时间是global.interactive_timeout。  
  14.   e. 2.3和2.4 , 3.3和3.4 这4个实验也间接验证实验1中的情况,cnf.interactive_timeout覆盖wait_timeout,起作用的是cnf.interactive_timeout和global.interactive_timeout。  
  15.   f.从这8个实验可以看出:对于修改wait_timeout和interactive_timeout(包括session和global),只会修改show [global] variables like '%time%';中的参数值,  
  16.     但是具体超时时间,并不以这两个值为准。---有点绕,需要理解。  
  17.   g. set global wait_timeout和interactive_timeout,修改了当前会话全局参数值,并不修改当前会话级别的值。  
  18.      只会对新建会话生效(set global wait_timeout和interactive_timeout之后创建的会话),  
  19.      对于已经创建的会话不生效(set global wait_timeout和interactive_timeout之前创建的会话)。  

[plain] view plain copy
  1. 1.修改my.cnf文件,分别设置wait_timeout和interactive_timeout不同的值,最终看谁覆盖谁?  
  2. 答:interactive_timeout会覆盖wait_timeout。  
  3.   
  4. 修改参数文件,重启mysql  
  5. # Connection timeout variables  
  6. wait_timeout=15  
  7. interactive_timeout=10  
  8.   
  9. >  show global variables like '%time%';  
  10. +---------------------------------+-------------------+  
  11. | Variable_name                   | Value             |  
  12. +---------------------------------+-------------------+  
  13. | binlog_max_flush_queue_time     | 0                 |  
  14. | connect_timeout                 | 10                |  
  15. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  16. | delayed_insert_timeout          | 300               |  
  17. | explicit_defaults_for_timestamp | OFF               |  
  18. | flush_time                      | 0                 |  
  19. | innodb_flush_log_at_timeout     | 1                 |  
  20. | innodb_lock_wait_timeout        | 50                |  
  21. | innodb_old_blocks_time          | 1000              |  
  22. | innodb_rollback_on_timeout      | OFF               |  
  23. | interactive_timeout             | 10                |  
  24. | lc_time_names                   | en_US             |  
  25. | lock_wait_timeout               | 31536000          |  
  26. | long_query_time                 | 0.020000          |  
  27. | net_read_timeout                | 30                |  
  28. | net_write_timeout               | 60                |  
  29. | rpl_stop_slave_timeout          | 31536000          |  
  30. | slave_net_timeout               | 3600              |  
  31. | slow_launch_time                | 2                 |  
  32. | system_time_zone                | CST               |  
  33. | time_format                     | %H:%i:%s          |  
  34. | time_zone                       | SYSTEM            |  
  35. | timed_mutexes                   | OFF               |  
  36. | wait_timeout                    | 15                |  
  37. +---------------------------------+-------------------+  
  38. 24 rows in set (0.00 sec)  
  39.   
  40. >  show  variables like '%time%';  
  41. +---------------------------------+-------------------+  
  42. | Variable_name                   | Value             |  
  43. +---------------------------------+-------------------+  
  44. | binlog_max_flush_queue_time     | 0                 |  
  45. | connect_timeout                 | 10                |  
  46. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  47. | delayed_insert_timeout          | 300               |  
  48. | explicit_defaults_for_timestamp | OFF               |  
  49. | flush_time                      | 0                 |  
  50. | innodb_flush_log_at_timeout     | 1                 |  
  51. | innodb_lock_wait_timeout        | 50                |  
  52. | innodb_old_blocks_time          | 1000              |  
  53. | innodb_rollback_on_timeout      | OFF               |  
  54. | interactive_timeout             | 10                |  
  55. | lc_time_names                   | en_US             |  
  56. | lock_wait_timeout               | 31536000          |  
  57. | long_query_time                 | 0.020000          |  
  58. | net_read_timeout                | 30                |  
  59. | net_write_timeout               | 60                |  
  60. | rpl_stop_slave_timeout          | 31536000          |  
  61. | slave_net_timeout               | 3600              |  
  62. | slow_launch_time                | 2                 |  
  63. | system_time_zone                | CST               |  
  64. | time_format                     | %H:%i:%s          |  
  65. | time_zone                       | SYSTEM            |  
  66. | timed_mutexes                   | OFF               |  
  67. | timestamp                       | 1442817811.601474 |  
  68. | wait_timeout                    | 10                |  
  69. +---------------------------------+-------------------+  
  70. 25 rows in set (0.00 sec)  
  71.   
  72. 查看会话超时时间 --- 会话超时时间是10s  
  73. > show full processlist;  
  74. +----+------+-----------+------+---------+------+-------+-----------------------+  
  75. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  76. +----+------+-----------+------+---------+------+-------+-----------------------+  
  77. |  2 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  78. |  3 | ca   | localhost | NULL | Sleep   |   10 |       | NULL                  |  
  79. +----+------+-----------+------+---------+------+-------+-----------------------+  
  80. 2 rows in set (0.00 sec)  
  81.   
  82. (casystem)root@localhost [(none)]> show full processlist;  
  83. +----+------+-----------+------+---------+------+-------+-----------------------+  
  84. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  85. +----+------+-----------+------+---------+------+-------+-----------------------+  
  86. |  2 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  87. +----+------+-----------+------+---------+------+-------+-----------------------+  
  88. 1 row in set (0.00 sec)  
  89.   
  90.   
  91.   
  92. 修改参数文件,重启mysql  
  93. # Connection timeout variables  
  94. wait_timeout=10  
  95. interactive_timeout=15  
  96.   
  97. >  show global variables like '%time%';  
  98. +---------------------------------+-------------------+  
  99. | Variable_name                   | Value             |  
  100. +---------------------------------+-------------------+  
  101. | binlog_max_flush_queue_time     | 0                 |  
  102. | connect_timeout                 | 10                |  
  103. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  104. | delayed_insert_timeout          | 300               |  
  105. | explicit_defaults_for_timestamp | OFF               |  
  106. | flush_time                      | 0                 |  
  107. | innodb_flush_log_at_timeout     | 1                 |  
  108. | innodb_lock_wait_timeout        | 50                |  
  109. | innodb_old_blocks_time          | 1000              |  
  110. | innodb_rollback_on_timeout      | OFF               |  
  111. | interactive_timeout             | 15                |  
  112. | lc_time_names                   | en_US             |  
  113. | lock_wait_timeout               | 31536000          |  
  114. | long_query_time                 | 0.020000          |  
  115. | net_read_timeout                | 30                |  
  116. | net_write_timeout               | 60                |  
  117. | rpl_stop_slave_timeout          | 31536000          |  
  118. | slave_net_timeout               | 3600              |  
  119. | slow_launch_time                | 2                 |  
  120. | system_time_zone                | CST               |  
  121. | time_format                     | %H:%i:%s          |  
  122. | time_zone                       | SYSTEM            |  
  123. | timed_mutexes                   | OFF               |  
  124. | wait_timeout                    | 10                |  
  125. +---------------------------------+-------------------+  
  126. 24 rows in set (0.00 sec)  
  127.   
  128. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  129. +---------------------------------+-------------------+  
  130. | Variable_name                   | Value             |  
  131. +---------------------------------+-------------------+  
  132. | binlog_max_flush_queue_time     | 0                 |  
  133. | connect_timeout                 | 10                |  
  134. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  135. | delayed_insert_timeout          | 300               |  
  136. | explicit_defaults_for_timestamp | OFF               |  
  137. | flush_time                      | 0                 |  
  138. | innodb_flush_log_at_timeout     | 1                 |  
  139. | innodb_lock_wait_timeout        | 50                |  
  140. | innodb_old_blocks_time          | 1000              |  
  141. | innodb_rollback_on_timeout      | OFF               |  
  142. | interactive_timeout             | 15                |  
  143. | lc_time_names                   | en_US             |  
  144. | lock_wait_timeout               | 31536000          |  
  145. | long_query_time                 | 0.020000          |  
  146. | net_read_timeout                | 30                |  
  147. | net_write_timeout               | 60                |  
  148. | rpl_stop_slave_timeout          | 31536000          |  
  149. | slave_net_timeout               | 3600              |  
  150. | slow_launch_time                | 2                 |  
  151. | system_time_zone                | CST               |  
  152. | time_format                     | %H:%i:%s          |  
  153. | time_zone                       | SYSTEM            |  
  154. | timed_mutexes                   | OFF               |  
  155. | timestamp                       | 1442817650.922342 |  
  156. | wait_timeout                    | 15                |  
  157. +---------------------------------+-------------------+  
  158. 25 rows in set (0.01 sec)  
  159.   
  160. 查看会话超时时间 --会话超时时间是15秒  
  161. > show full processlist;  
  162. +----+------+-----------+------+---------+------+-------+-----------------------+  
  163. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  164. +----+------+-----------+------+---------+------+-------+-----------------------+  
  165. |  2 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  166. |  4 | ca   | localhost | NULL | Sleep   |   15 |       | NULL                  |  
  167. +----+------+-----------+------+---------+------+-------+-----------------------+  
  168. 2 rows in set (0.00 sec)  
  169.   
  170. (casystem)root@localhost [(none)]> show full processlist;  
  171. +----+------+-----------+------+---------+------+-------+-----------------------+  
  172. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  173. +----+------+-----------+------+---------+------+-------+-----------------------+  
  174. |  2 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  175. +----+------+-----------+------+---------+------+-------+-----------------------+  
  176. 1 row in set (0.00 sec)  




[plain] view plain copy
  1. 2.interactive_timeout对wait_timeout的影响。--下面测试的参数文件是  
  2. # Connection timeout variables  
  3. wait_timeout=15  
  4. interactive_timeout=10  
  5.   
  6. >  show  variables like '%time%';  
  7. +---------------------------------+-------------------+  
  8. | Variable_name                   | Value             |  
  9. +---------------------------------+-------------------+  
  10. | binlog_max_flush_queue_time     | 0                 |  
  11. | connect_timeout                 | 10                |  
  12. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  13. | delayed_insert_timeout          | 300               |  
  14. | explicit_defaults_for_timestamp | OFF               |  
  15. | flush_time                      | 0                 |  
  16. | innodb_flush_log_at_timeout     | 1                 |  
  17. | innodb_lock_wait_timeout        | 50                |  
  18. | innodb_old_blocks_time          | 1000              |  
  19. | innodb_rollback_on_timeout      | OFF               |  
  20. | interactive_timeout             | 10                |  
  21. | lc_time_names                   | en_US             |  
  22. | lock_wait_timeout               | 31536000          |  
  23. | long_query_time                 | 0.020000          |  
  24. | net_read_timeout                | 30                |  
  25. | net_write_timeout               | 60                |  
  26. | rpl_stop_slave_timeout          | 31536000          |  
  27. | slave_net_timeout               | 3600              |  
  28. | slow_launch_time                | 2                 |  
  29. | system_time_zone                | CST               |  
  30. | time_format                     | %H:%i:%s          |  
  31. | time_zone                       | SYSTEM            |  
  32. | timed_mutexes                   | OFF               |  
  33. | timestamp                       | 1442818199.946527 |  
  34. | wait_timeout                    | 10                |  
  35. +---------------------------------+-------------------+  
  36. 25 rows in set (0.01 sec)  
  37.   
  38. >  show global variables like '%time%';  
  39. +---------------------------------+-------------------+  
  40. | Variable_name                   | Value             |  
  41. +---------------------------------+-------------------+  
  42. | binlog_max_flush_queue_time     | 0                 |  
  43. | connect_timeout                 | 10                |  
  44. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  45. | delayed_insert_timeout          | 300               |  
  46. | explicit_defaults_for_timestamp | OFF               |  
  47. | flush_time                      | 0                 |  
  48. | innodb_flush_log_at_timeout     | 1                 |  
  49. | innodb_lock_wait_timeout        | 50                |  
  50. | innodb_old_blocks_time          | 1000              |  
  51. | innodb_rollback_on_timeout      | OFF               |  
  52. | interactive_timeout             | 10                |  
  53. | lc_time_names                   | en_US             |  
  54. | lock_wait_timeout               | 31536000          |  
  55. | long_query_time                 | 0.020000          |  
  56. | net_read_timeout                | 30                |  
  57. | net_write_timeout               | 60                |  
  58. | rpl_stop_slave_timeout          | 31536000          |  
  59. | slave_net_timeout               | 3600              |  
  60. | slow_launch_time                | 2                 |  
  61. | system_time_zone                | CST               |  
  62. | time_format                     | %H:%i:%s          |  
  63. | time_zone                       | SYSTEM            |  
  64. | timed_mutexes                   | OFF               |  
  65. | wait_timeout                    | 15                |  
  66. +---------------------------------+-------------------+  
  67. 24 rows in set (0.00 sec)  

[plain] view plain copy
  1. 2.1 session.interactive_timeout<cnf.interactive_timeout  时,session.interactive_timeout是否会覆盖wait_timeout?  
  2. set interactive_timeout=8;  (8<10)  
  3.   
  4. > set interactive_timeout=8;  
  5. Query OK, 0 rows affected (0.00 sec)  
  6.   
  7. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  8. +---------------------------------+-------------------+  
  9. | Variable_name                   | Value             |  
  10. +---------------------------------+-------------------+  
  11. | binlog_max_flush_queue_time     | 0                 |  
  12. | connect_timeout                 | 10                |  
  13. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  14. | delayed_insert_timeout          | 300               |  
  15. | explicit_defaults_for_timestamp | OFF               |  
  16. | flush_time                      | 0                 |  
  17. | innodb_flush_log_at_timeout     | 1                 |  
  18. | innodb_lock_wait_timeout        | 50                |  
  19. | innodb_old_blocks_time          | 1000              |  
  20. | innodb_rollback_on_timeout      | OFF               |  
  21. | interactive_timeout             | 10                |  
  22. | lc_time_names                   | en_US             |  
  23. | lock_wait_timeout               | 31536000          |  
  24. | long_query_time                 | 0.020000          |  
  25. | net_read_timeout                | 30                |  
  26. | net_write_timeout               | 60                |  
  27. | rpl_stop_slave_timeout          | 31536000          |  
  28. | slave_net_timeout               | 3600              |  
  29. | slow_launch_time                | 2                 |  
  30. | system_time_zone                | CST               |  
  31. | time_format                     | %H:%i:%s          |  
  32. | time_zone                       | SYSTEM            |  
  33. | timed_mutexes                   | OFF               |  
  34. | wait_timeout                    | 15                |  
  35. +---------------------------------+-------------------+  
  36. 24 rows in set (0.00 sec)  
  37.   
  38. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  39. +---------------------------------+-------------------+  
  40. | Variable_name                   | Value             |  
  41. +---------------------------------+-------------------+  
  42. | binlog_max_flush_queue_time     | 0                 |  
  43. | connect_timeout                 | 10                |  
  44. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  45. | delayed_insert_timeout          | 300               |  
  46. | explicit_defaults_for_timestamp | OFF               |  
  47. | flush_time                      | 0                 |  
  48. | innodb_flush_log_at_timeout     | 1                 |  
  49. | innodb_lock_wait_timeout        | 50                |  
  50. | innodb_old_blocks_time          | 1000              |  
  51. | innodb_rollback_on_timeout      | OFF               |  
  52. | interactive_timeout             | 8                 |  
  53. | lc_time_names                   | en_US             |  
  54. | lock_wait_timeout               | 31536000          |  
  55. | long_query_time                 | 0.020000          |  
  56. | net_read_timeout                | 30                |  
  57. | net_write_timeout               | 60                |  
  58. | rpl_stop_slave_timeout          | 31536000          |  
  59. | slave_net_timeout               | 3600              |  
  60. | slow_launch_time                | 2                 |  
  61. | system_time_zone                | CST               |  
  62. | time_format                     | %H:%i:%s          |  
  63. | time_zone                       | SYSTEM            |  
  64. | timed_mutexes                   | OFF               |  
  65. | timestamp                       | 1442818460.657640 |  
  66. | wait_timeout                    | 10                |  
  67. +---------------------------------+-------------------+  
  68. 25 rows in set (0.00 sec)  
  69.   
  70. 当前会话超时时间----------- 超时时间是10s(不是8s),修改会话级的interactive_timeout没有覆盖wait_timeout。  
  71. (casystem)root@localhost [(none)]> show full processlist;  
  72. +----+------+-----------+------+---------+------+-------+-----------------------+  
  73. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  74. +----+------+-----------+------+---------+------+-------+-----------------------+  
  75. |  5 | ca   | localhost | NULL | Sleep   |   10 |       | NULL                  |  
  76. |  6 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  77. +----+------+-----------+------+---------+------+-------+-----------------------+  
  78. 2 rows in set (0.00 sec)  
  79.   
  80. (casystem)root@localhost [(none)]> show full processlist;  
  81. +----+------+-----------+------+---------+------+-------+-----------------------+  
  82. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  83. +----+------+-----------+------+---------+------+-------+-----------------------+  
  84. |  6 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  85. +----+------+-----------+------+---------+------+-------+-----------------------+  
  86. 1 row in set (0.00 sec)  

[plain] view plain copy
  1. 2.2 session.interactive_timeout>cnf.interactive_timeout 时,session.interactive_timeout是否会覆盖wait_timeout?  
  2.   
  3. > set interactive_timeout=12;  
  4. Query OK, 0 rows affected (0.00 sec)  
  5.   
  6. >  show  variables like '%time%';  
  7. +---------------------------------+-------------------+  
  8. | Variable_name                   | Value             |  
  9. +---------------------------------+-------------------+  
  10. | binlog_max_flush_queue_time     | 0                 |  
  11. | connect_timeout                 | 10                |  
  12. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  13. | delayed_insert_timeout          | 300               |  
  14. | explicit_defaults_for_timestamp | OFF               |  
  15. | flush_time                      | 0                 |  
  16. | innodb_flush_log_at_timeout     | 1                 |  
  17. | innodb_lock_wait_timeout        | 50                |  
  18. | innodb_old_blocks_time          | 1000              |  
  19. | innodb_rollback_on_timeout      | OFF               |  
  20. | interactive_timeout             | 12                |  
  21. | lc_time_names                   | en_US             |  
  22. | lock_wait_timeout               | 31536000          |  
  23. | long_query_time                 | 0.020000          |  
  24. | net_read_timeout                | 30                |  
  25. | net_write_timeout               | 60                |  
  26. | rpl_stop_slave_timeout          | 31536000          |  
  27. | slave_net_timeout               | 3600              |  
  28. | slow_launch_time                | 2                 |  
  29. | system_time_zone                | CST               |  
  30. | time_format                     | %H:%i:%s          |  
  31. | time_zone                       | SYSTEM            |  
  32. | timed_mutexes                   | OFF               |  
  33. | timestamp                       | 1442818758.020616 |  
  34. | wait_timeout                    | 10                |  
  35. +---------------------------------+-------------------+  
  36. 25 rows in set (0.01 sec)  
  37.   
  38. >  show global variables like '%time%';  
  39. +---------------------------------+-------------------+  
  40. | Variable_name                   | Value             |  
  41. +---------------------------------+-------------------+  
  42. | binlog_max_flush_queue_time     | 0                 |  
  43. | connect_timeout                 | 10                |  
  44. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  45. | delayed_insert_timeout          | 300               |  
  46. | explicit_defaults_for_timestamp | OFF               |  
  47. | flush_time                      | 0                 |  
  48. | innodb_flush_log_at_timeout     | 1                 |  
  49. | innodb_lock_wait_timeout        | 50                |  
  50. | innodb_old_blocks_time          | 1000              |  
  51. | innodb_rollback_on_timeout      | OFF               |  
  52. | interactive_timeout             | 10                |  
  53. | lc_time_names                   | en_US             |  
  54. | lock_wait_timeout               | 31536000          |  
  55. | long_query_time                 | 0.020000          |  
  56. | net_read_timeout                | 30                |  
  57. | net_write_timeout               | 60                |  
  58. | rpl_stop_slave_timeout          | 31536000          |  
  59. | slave_net_timeout               | 3600              |  
  60. | slow_launch_time                | 2                 |  
  61. | system_time_zone                | CST               |  
  62. | time_format                     | %H:%i:%s          |  
  63. | time_zone                       | SYSTEM            |  
  64. | timed_mutexes                   | OFF               |  
  65. | wait_timeout                    | 15                |  
  66. +---------------------------------+-------------------+  
  67. 24 rows in set (0.00 sec)  
  68.   
  69. 当前会话超时时间----------- 超时时间是10s(不是12s),修改会话级的interactive_timeout没有覆盖wait_timeout。  
  70. (casystem)root@localhost [(none)]> show full processlist;  
  71. +----+------+-----------+------+---------+------+-------+-----------------------+  
  72. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  73. +----+------+-----------+------+---------+------+-------+-----------------------+  
  74. | 10 | ca   | localhost | NULL | Sleep   |   10 |       | NULL                  |  
  75. | 11 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  76. +----+------+-----------+------+---------+------+-------+-----------------------+  
  77. 2 rows in set (0.00 sec)  
  78.   
  79. (casystem)root@localhost [(none)]> show full processlist;  
  80. +----+------+-----------+------+---------+------+-------+-----------------------+  
  81. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  82. +----+------+-----------+------+---------+------+-------+-----------------------+  
  83. | 11 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  84. +----+------+-----------+------+---------+------+-------+-----------------------+  
  85. 1 row in set (0.01 sec)  

[plain] view plain copy
  1. 2.3 global.interactive_timeout<cnf.interactive_timeout 时,global.interactive_timeout是否会覆盖wait_timeout?  
  2. set global interactive_timeout=8;  
  3.   
  4. 当前会话  --- 当前会话的超时时间还是10秒,并未马上修改成8秒。等当前会话超时之后,才重新修改成了8秒。  
  5. > set global interactive_timeout=8;  
  6. Query OK, 0 rows affected (0.00 sec)  
  7.   
  8. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  9. +---------------------------------+-------------------+  
  10. | Variable_name                   | Value             |  
  11. +---------------------------------+-------------------+  
  12. | binlog_max_flush_queue_time     | 0                 |  
  13. | connect_timeout                 | 10                |  
  14. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  15. | delayed_insert_timeout          | 300               |  
  16. | explicit_defaults_for_timestamp | OFF               |  
  17. | flush_time                      | 0                 |  
  18. | innodb_flush_log_at_timeout     | 1                 |  
  19. | innodb_lock_wait_timeout        | 50                |  
  20. | innodb_old_blocks_time          | 1000              |  
  21. | innodb_rollback_on_timeout      | OFF               |  
  22. | interactive_timeout             | 8                 |  
  23. | lc_time_names                   | en_US             |  
  24. | lock_wait_timeout               | 31536000          |  
  25. | long_query_time                 | 0.020000          |  
  26. | net_read_timeout                | 30                |  
  27. | net_write_timeout               | 60                |  
  28. | rpl_stop_slave_timeout          | 31536000          |  
  29. | slave_net_timeout               | 3600              |  
  30. | slow_launch_time                | 2                 |  
  31. | system_time_zone                | CST               |  
  32. | time_format                     | %H:%i:%s          |  
  33. | time_zone                       | SYSTEM            |  
  34. | timed_mutexes                   | OFF               |  
  35. | wait_timeout                    | 15                |  
  36. +---------------------------------+-------------------+  
  37. 24 rows in set (0.00 sec)  
  38.   
  39. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  40. +---------------------------------+-------------------+  
  41. | Variable_name                   | Value             |  
  42. +---------------------------------+-------------------+  
  43. | binlog_max_flush_queue_time     | 0                 |  
  44. | connect_timeout                 | 10                |  
  45. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  46. | delayed_insert_timeout          | 300               |  
  47. | explicit_defaults_for_timestamp | OFF               |  
  48. | flush_time                      | 0                 |  
  49. | innodb_flush_log_at_timeout     | 1                 |  
  50. | innodb_lock_wait_timeout        | 50                |  
  51. | innodb_old_blocks_time          | 1000              |  
  52. | innodb_rollback_on_timeout      | OFF               |  
  53. | interactive_timeout             | 10                |  
  54. | lc_time_names                   | en_US             |  
  55. | lock_wait_timeout               | 31536000          |  
  56. | long_query_time                 | 0.020000          |  
  57. | net_read_timeout                | 30                |  
  58. | net_write_timeout               | 60                |  
  59. | rpl_stop_slave_timeout          | 31536000          |  
  60. | slave_net_timeout               | 3600              |  
  61. | slow_launch_time                | 2                 |  
  62. | system_time_zone                | CST               |  
  63. | time_format                     | %H:%i:%s          |  
  64. | time_zone                       | SYSTEM            |  
  65. | timed_mutexes                   | OFF               |  
  66. | timestamp                       | 1442819026.134650 |  
  67. | wait_timeout                    | 10                |  
  68. +---------------------------------+-------------------+  
  69. 25 rows in set (0.00 sec)  
  70. >  show  variables like '%time%';  
  71. ERROR 2006 (HY000): MySQL server has gone away  
  72. No connection. Trying to reconnect...  
  73. Connection id:    22  
  74. Current database: *** NONE ***  
  75.   
  76. +---------------------------------+-------------------+  
  77. | Variable_name                   | Value             |  
  78. +---------------------------------+-------------------+  
  79. | binlog_max_flush_queue_time     | 0                 |  
  80. | connect_timeout                 | 10                |  
  81. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  82. | delayed_insert_timeout          | 300               |  
  83. | explicit_defaults_for_timestamp | OFF               |  
  84. | flush_time                      | 0                 |  
  85. | innodb_flush_log_at_timeout     | 1                 |  
  86. | innodb_lock_wait_timeout        | 50                |  
  87. | innodb_old_blocks_time          | 1000              |  
  88. | innodb_rollback_on_timeout      | OFF               |  
  89. | interactive_timeout             | 8                 |  
  90. | lc_time_names                   | en_US             |  
  91. | lock_wait_timeout               | 31536000          |  
  92. | long_query_time                 | 0.020000          |  
  93. | net_read_timeout                | 30                |  
  94. | net_write_timeout               | 60                |  
  95. | rpl_stop_slave_timeout          | 31536000          |  
  96. | slave_net_timeout               | 3600              |  
  97. | slow_launch_time                | 2                 |  
  98. | system_time_zone                | CST               |  
  99. | time_format                     | %H:%i:%s          |  
  100. | time_zone                       | SYSTEM            |  
  101. | timed_mutexes                   | OFF               |  
  102. | timestamp                       | 1442819970.559386 |  
  103. | wait_timeout                    | 8                 |  
  104. +---------------------------------+-------------------+  
  105. 25 rows in set (0.00 sec)  
  106.   
  107.   
  108.   
  109. 新建的会话---新的会话修改成了8秒,而且新会话的interactive_timeout和wait_timeout都是8秒,全局的interactive_timeout=8秒,全局的wait_timeout=15保持不变。  
  110. > show global variables like '%time%';  
  111. +---------------------------------+-------------------+  
  112. | Variable_name                   | Value             |  
  113. +---------------------------------+-------------------+  
  114. | binlog_max_flush_queue_time     | 0                 |  
  115. | connect_timeout                 | 10                |  
  116. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  117. | delayed_insert_timeout          | 300               |  
  118. | explicit_defaults_for_timestamp | OFF               |  
  119. | flush_time                      | 0                 |  
  120. | innodb_flush_log_at_timeout     | 1                 |  
  121. | innodb_lock_wait_timeout        | 50                |  
  122. | innodb_old_blocks_time          | 1000              |  
  123. | innodb_rollback_on_timeout      | OFF               |  
  124. | interactive_timeout             | 8                 |  
  125. | lc_time_names                   | en_US             |  
  126. | lock_wait_timeout               | 31536000          |  
  127. | long_query_time                 | 0.020000          |  
  128. | net_read_timeout                | 30                |  
  129. | net_write_timeout               | 60                |  
  130. | rpl_stop_slave_timeout          | 31536000          |  
  131. | slave_net_timeout               | 3600              |  
  132. | slow_launch_time                | 2                 |  
  133. | system_time_zone                | CST               |  
  134. | time_format                     | %H:%i:%s          |  
  135. | time_zone                       | SYSTEM            |  
  136. | timed_mutexes                   | OFF               |  
  137. | wait_timeout                    | 15                |  
  138. +---------------------------------+-------------------+  
  139. 24 rows in set (0.00 sec)  
  140.   
  141. (casystem)ca@localhost [(none)]> show  variables like '%time%';  
  142. +---------------------------------+-------------------+  
  143. | Variable_name                   | Value             |  
  144. +---------------------------------+-------------------+  
  145. | binlog_max_flush_queue_time     | 0                 |  
  146. | connect_timeout                 | 10                |  
  147. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  148. | delayed_insert_timeout          | 300               |  
  149. | explicit_defaults_for_timestamp | OFF               |  
  150. | flush_time                      | 0                 |  
  151. | innodb_flush_log_at_timeout     | 1                 |  
  152. | innodb_lock_wait_timeout        | 50                |  
  153. | innodb_old_blocks_time          | 1000              |  
  154. | innodb_rollback_on_timeout      | OFF               |  
  155. | interactive_timeout             | 8                 |  
  156. | lc_time_names                   | en_US             |  
  157. | lock_wait_timeout               | 31536000          |  
  158. | long_query_time                 | 0.020000          |  
  159. | net_read_timeout                | 30                |  
  160. | net_write_timeout               | 60                |  
  161. | rpl_stop_slave_timeout          | 31536000          |  
  162. | slave_net_timeout               | 3600              |  
  163. | slow_launch_time                | 2                 |  
  164. | system_time_zone                | CST               |  
  165. | time_format                     | %H:%i:%s          |  
  166. | time_zone                       | SYSTEM            |  
  167. | timed_mutexes                   | OFF               |  
  168. | timestamp                       | 1442819080.061477 |  
  169. | wait_timeout                    | 8                 |  
  170. +---------------------------------+-------------------+  
  171. 25 rows in set (0.00 sec)  

[plain] view plain copy
  1. 2.4 global.interactive_timeout>cnf.interactive_timeout 时,global.interactive_timeout是否会覆盖wait_timeout?  
  2.   
  3. 当前会话  --- 当前会话的超时时间并未马上修改成12秒。等当前会话超时之后,才重新修改成了12秒。  
  4. > set global interactive_timeout=12;  
  5. Query OK, 0 rows affected (0.00 sec)  
  6.   
  7. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  8. +---------------------------------+-------------------+  
  9. | Variable_name                   | Value             |  
  10. +---------------------------------+-------------------+  
  11. | binlog_max_flush_queue_time     | 0                 |  
  12. | connect_timeout                 | 10                |  
  13. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  14. | delayed_insert_timeout          | 300               |  
  15. | explicit_defaults_for_timestamp | OFF               |  
  16. | flush_time                      | 0                 |  
  17. | innodb_flush_log_at_timeout     | 1                 |  
  18. | innodb_lock_wait_timeout        | 50                |  
  19. | innodb_old_blocks_time          | 1000              |  
  20. | innodb_rollback_on_timeout      | OFF               |  
  21. | interactive_timeout             | 12                |  
  22. | lc_time_names                   | en_US             |  
  23. | lock_wait_timeout               | 31536000          |  
  24. | long_query_time                 | 0.020000          |  
  25. | net_read_timeout                | 30                |  
  26. | net_write_timeout               | 60                |  
  27. | rpl_stop_slave_timeout          | 31536000          |  
  28. | slave_net_timeout               | 3600              |  
  29. | slow_launch_time                | 2                 |  
  30. | system_time_zone                | CST               |  
  31. | time_format                     | %H:%i:%s          |  
  32. | time_zone                       | SYSTEM            |  
  33. | timed_mutexes                   | OFF               |  
  34. | wait_timeout                    | 15                |  
  35. +---------------------------------+-------------------+  
  36. 24 rows in set (0.00 sec)  
  37.   
  38. >  show  variables like '%time%';  --当前会话没有立马生效,等了“一会儿”  
  39. ERROR 2006 (HY000): MySQL server has gone away  
  40. No connection. Trying to reconnect...  
  41. Connection id:    17  
  42. Current database: *** NONE ***  
  43.   
  44. +---------------------------------+-------------------+  
  45. | Variable_name                   | Value             |  
  46. +---------------------------------+-------------------+  
  47. | binlog_max_flush_queue_time     | 0                 |  
  48. | connect_timeout                 | 10                |  
  49. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  50. | delayed_insert_timeout          | 300               |  
  51. | explicit_defaults_for_timestamp | OFF               |  
  52. | flush_time                      | 0                 |  
  53. | innodb_flush_log_at_timeout     | 1                 |  
  54. | innodb_lock_wait_timeout        | 50                |  
  55. | innodb_old_blocks_time          | 1000              |  
  56. | innodb_rollback_on_timeout      | OFF               |  
  57. | interactive_timeout             | 12                |  
  58. | lc_time_names                   | en_US             |  
  59. | lock_wait_timeout               | 31536000          |  
  60. | long_query_time                 | 0.020000          |  
  61. | net_read_timeout                | 30                |  
  62. | net_write_timeout               | 60                |  
  63. | rpl_stop_slave_timeout          | 31536000          |  
  64. | slave_net_timeout               | 3600              |  
  65. | slow_launch_time                | 2                 |  
  66. | system_time_zone                | CST               |  
  67. | time_format                     | %H:%i:%s          |  
  68. | time_zone                       | SYSTEM            |  
  69. | timed_mutexes                   | OFF               |  
  70. | timestamp                       | 1442819701.923548 |  
  71. | wait_timeout                    | 12                |  
  72. +---------------------------------+-------------------+  
  73. 25 rows in set (0.01 sec)  
  74.   
  75. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  76. +---------------------------------+-------------------+  
  77. | Variable_name                   | Value             |  
  78. +---------------------------------+-------------------+  
  79. | binlog_max_flush_queue_time     | 0                 |  
  80. | connect_timeout                 | 10                |  
  81. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  82. | delayed_insert_timeout          | 300               |  
  83. | explicit_defaults_for_timestamp | OFF               |  
  84. | flush_time                      | 0                 |  
  85. | innodb_flush_log_at_timeout     | 1                 |  
  86. | innodb_lock_wait_timeout        | 50                |  
  87. | innodb_old_blocks_time          | 1000              |  
  88. | innodb_rollback_on_timeout      | OFF               |  
  89. | interactive_timeout             | 12                |  
  90. | lc_time_names                   | en_US             |  
  91. | lock_wait_timeout               | 31536000          |  
  92. | long_query_time                 | 0.020000          |  
  93. | net_read_timeout                | 30                |  
  94. | net_write_timeout               | 60                |  
  95. | rpl_stop_slave_timeout          | 31536000          |  
  96. | slave_net_timeout               | 3600              |  
  97. | slow_launch_time                | 2                 |  
  98. | system_time_zone                | CST               |  
  99. | time_format                     | %H:%i:%s          |  
  100. | time_zone                       | SYSTEM            |  
  101. | timed_mutexes                   | OFF               |  
  102. | wait_timeout                    | 15                |  
  103. +---------------------------------+-------------------+  
  104. 24 rows in set (0.01 sec)  
  105.   
  106. 当前会话的超时时间  
  107. > show full processlist;  
  108. +----+------+-----------+------+---------+------+-------+-----------------------+  
  109. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  110. +----+------+-----------+------+---------+------+-------+-----------------------+  
  111. | 18 | ca   | localhost | NULL | Sleep   |   12 |       | NULL                  |  
  112. | 19 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  113. +----+------+-----------+------+---------+------+-------+-----------------------+  
  114. 2 rows in set (0.00 sec)  
  115.   
  116. (casystem)root@localhost [(none)]> show full processlist;  
  117. +----+------+-----------+------+---------+------+-------+-----------------------+  
  118. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  119. +----+------+-----------+------+---------+------+-------+-----------------------+  
  120. | 19 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  121. +----+------+-----------+------+---------+------+-------+-----------------------+  
  122. 1 row in set (0.00 sec)  
  123.   
  124. 新会话-------  
  125. > show  variables like '%time%';  
  126. +---------------------------------+-------------------+  
  127. | Variable_name                   | Value             |  
  128. +---------------------------------+-------------------+  
  129. | binlog_max_flush_queue_time     | 0                 |  
  130. | connect_timeout                 | 10                |  
  131. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  132. | delayed_insert_timeout          | 300               |  
  133. | explicit_defaults_for_timestamp | OFF               |  
  134. | flush_time                      | 0                 |  
  135. | innodb_flush_log_at_timeout     | 1                 |  
  136. | innodb_lock_wait_timeout        | 50                |  
  137. | innodb_old_blocks_time          | 1000              |  
  138. | innodb_rollback_on_timeout      | OFF               |  
  139. | interactive_timeout             | 12                |  
  140. | lc_time_names                   | en_US             |  
  141. | lock_wait_timeout               | 31536000          |  
  142. | long_query_time                 | 0.020000          |  
  143. | net_read_timeout                | 30                |  
  144. | net_write_timeout               | 60                |  
  145. | rpl_stop_slave_timeout          | 31536000          |  
  146. | slave_net_timeout               | 3600              |  
  147. | slow_launch_time                | 2                 |  
  148. | system_time_zone                | CST               |  
  149. | time_format                     | %H:%i:%s          |  
  150. | time_zone                       | SYSTEM            |  
  151. | timed_mutexes                   | OFF               |  
  152. | timestamp                       | 1442819629.180842 |  
  153. | wait_timeout                    | 12                |  
  154. +---------------------------------+-------------------+  
  155. 25 rows in set (0.00 sec)  
  156.   
  157. (casystem)ca@localhost [(none)]> show global variables like '%time%';  
  158. +---------------------------------+-------------------+  
  159. | Variable_name                   | Value             |  
  160. +---------------------------------+-------------------+  
  161. | binlog_max_flush_queue_time     | 0                 |  
  162. | connect_timeout                 | 10                |  
  163. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  164. | delayed_insert_timeout          | 300               |  
  165. | explicit_defaults_for_timestamp | OFF               |  
  166. | flush_time                      | 0                 |  
  167. | innodb_flush_log_at_timeout     | 1                 |  
  168. | innodb_lock_wait_timeout        | 50                |  
  169. | innodb_old_blocks_time          | 1000              |  
  170. | innodb_rollback_on_timeout      | OFF               |  
  171. | interactive_timeout             | 12                |  
  172. | lc_time_names                   | en_US             |  
  173. | lock_wait_timeout               | 31536000          |  
  174. | long_query_time                 | 0.020000          |  
  175. | net_read_timeout                | 30                |  
  176. | net_write_timeout               | 60                |  
  177. | rpl_stop_slave_timeout          | 31536000          |  
  178. | slave_net_timeout               | 3600              |  
  179. | slow_launch_time                | 2                 |  
  180. | system_time_zone                | CST               |  
  181. | time_format                     | %H:%i:%s          |  
  182. | time_zone                       | SYSTEM            |  
  183. | timed_mutexes                   | OFF               |  
  184. | wait_timeout                    | 15                |  
  185. +---------------------------------+-------------------+  
  186. 24 rows in set (0.00 sec)  
  187.   
  188. 新会话的超时时间,不测了。  

[plain] view plain copy
  1. 3.wait_timeout对interactive_timeout的影响。--下面测试的参数文件是  
  2. # Connection timeout variables  
  3. wait_timeout=15  
  4. interactive_timeout=10  
  5.   
  6. >  show  variables like '%time%';  
  7. +---------------------------------+-------------------+  
  8. | Variable_name                   | Value             |  
  9. +---------------------------------+-------------------+  
  10. | binlog_max_flush_queue_time     | 0                 |  
  11. | connect_timeout                 | 10                |  
  12. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  13. | delayed_insert_timeout          | 300               |  
  14. | explicit_defaults_for_timestamp | OFF               |  
  15. | flush_time                      | 0                 |  
  16. | innodb_flush_log_at_timeout     | 1                 |  
  17. | innodb_lock_wait_timeout        | 50                |  
  18. | innodb_old_blocks_time          | 1000              |  
  19. | innodb_rollback_on_timeout      | OFF               |  
  20. | interactive_timeout             | 10                |  
  21. | lc_time_names                   | en_US             |  
  22. | lock_wait_timeout               | 31536000          |  
  23. | long_query_time                 | 0.020000          |  
  24. | net_read_timeout                | 30                |  
  25. | net_write_timeout               | 60                |  
  26. | rpl_stop_slave_timeout          | 31536000          |  
  27. | slave_net_timeout               | 3600              |  
  28. | slow_launch_time                | 2                 |  
  29. | system_time_zone                | CST               |  
  30. | time_format                     | %H:%i:%s          |  
  31. | time_zone                       | SYSTEM            |  
  32. | timed_mutexes                   | OFF               |  
  33. | timestamp                       | 1442818199.946527 |  
  34. | wait_timeout                    | 10                |  
  35. +---------------------------------+-------------------+  
  36. 25 rows in set (0.01 sec)  
  37.   
  38. >  show global variables like '%time%';  
  39. +---------------------------------+-------------------+  
  40. | Variable_name                   | Value             |  
  41. +---------------------------------+-------------------+  
  42. | binlog_max_flush_queue_time     | 0                 |  
  43. | connect_timeout                 | 10                |  
  44. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  45. | delayed_insert_timeout          | 300               |  
  46. | explicit_defaults_for_timestamp | OFF               |  
  47. | flush_time                      | 0                 |  
  48. | innodb_flush_log_at_timeout     | 1                 |  
  49. | innodb_lock_wait_timeout        | 50                |  
  50. | innodb_old_blocks_time          | 1000              |  
  51. | innodb_rollback_on_timeout      | OFF               |  
  52. | interactive_timeout             | 10                |  
  53. | lc_time_names                   | en_US             |  
  54. | lock_wait_timeout               | 31536000          |  
  55. | long_query_time                 | 0.020000          |  
  56. | net_read_timeout                | 30                |  
  57. | net_write_timeout               | 60                |  
  58. | rpl_stop_slave_timeout          | 31536000          |  
  59. | slave_net_timeout               | 3600              |  
  60. | slow_launch_time                | 2                 |  
  61. | system_time_zone                | CST               |  
  62. | time_format                     | %H:%i:%s          |  
  63. | time_zone                       | SYSTEM            |  
  64. | timed_mutexes                   | OFF               |  
  65. | wait_timeout                    | 15                |  
  66. +---------------------------------+-------------------+  
  67. 24 rows in set (0.00 sec)  
  68.   
  69.   
  70. 3.1 session.wait_timeout<cnf.interactive_timeout时,session.wait_timeout是否会覆盖interactive_timeout?  
  71. set wait_timeout=8;  
  72.   
  73. > set wait_timeout=8;  
  74. Query OK, 0 rows affected (0.00 sec)  
  75.   
  76. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  77. +---------------------------------+-------------------+  
  78. | Variable_name                   | Value             |  
  79. +---------------------------------+-------------------+  
  80. | binlog_max_flush_queue_time     | 0                 |  
  81. | connect_timeout                 | 10                |  
  82. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  83. | delayed_insert_timeout          | 300               |  
  84. | explicit_defaults_for_timestamp | OFF               |  
  85. | flush_time                      | 0                 |  
  86. | innodb_flush_log_at_timeout     | 1                 |  
  87. | innodb_lock_wait_timeout        | 50                |  
  88. | innodb_old_blocks_time          | 1000              |  
  89. | innodb_rollback_on_timeout      | OFF               |  
  90. | interactive_timeout             | 10                |  
  91. | lc_time_names                   | en_US             |  
  92. | lock_wait_timeout               | 31536000          |  
  93. | long_query_time                 | 0.020000          |  
  94. | net_read_timeout                | 30                |  
  95. | net_write_timeout               | 60                |  
  96. | rpl_stop_slave_timeout          | 31536000          |  
  97. | slave_net_timeout               | 3600              |  
  98. | slow_launch_time                | 2                 |  
  99. | system_time_zone                | CST               |  
  100. | time_format                     | %H:%i:%s          |  
  101. | time_zone                       | SYSTEM            |  
  102. | timed_mutexes                   | OFF               |  
  103. | timestamp                       | 1442820543.624578 |  
  104. | wait_timeout                    | 8                 |  
  105. +---------------------------------+-------------------+  
  106. 25 rows in set (0.00 sec)  
  107.   
  108. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  109. +---------------------------------+-------------------+  
  110. | Variable_name                   | Value             |  
  111. +---------------------------------+-------------------+  
  112. | binlog_max_flush_queue_time     | 0                 |  
  113. | connect_timeout                 | 10                |  
  114. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  115. | delayed_insert_timeout          | 300               |  
  116. | explicit_defaults_for_timestamp | OFF               |  
  117. | flush_time                      | 0                 |  
  118. | innodb_flush_log_at_timeout     | 1                 |  
  119. | innodb_lock_wait_timeout        | 50                |  
  120. | innodb_old_blocks_time          | 1000              |  
  121. | innodb_rollback_on_timeout      | OFF               |  
  122. | interactive_timeout             | 10                |  
  123. | lc_time_names                   | en_US             |  
  124. | lock_wait_timeout               | 31536000          |  
  125. | long_query_time                 | 0.020000          |  
  126. | net_read_timeout                | 30                |  
  127. | net_write_timeout               | 60                |  
  128. | rpl_stop_slave_timeout          | 31536000          |  
  129. | slave_net_timeout               | 3600              |  
  130. | slow_launch_time                | 2                 |  
  131. | system_time_zone                | CST               |  
  132. | time_format                     | %H:%i:%s          |  
  133. | time_zone                       | SYSTEM            |  
  134. | timed_mutexes                   | OFF               |  
  135. | wait_timeout                    | 15                |  
  136. +---------------------------------+-------------------+  
  137. 24 rows in set (0.00 sec)  
  138.   
  139. 当前会话超时时间 -- 超时时间是interactive_timeout=10秒,不是8秒,修改当前会话的wait_timeout,没有覆盖interactive_timeout,起作用的是interactive_timeout  
  140. > show full processlist;  
  141. +----+------+-----------+------+---------+------+-------+-----------------------+  
  142. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  143. +----+------+-----------+------+---------+------+-------+-----------------------+  
  144. |  6 | ca   | localhost | NULL | Sleep   |   10 |       | NULL                  |  
  145. |  7 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  146. +----+------+-----------+------+---------+------+-------+-----------------------+  
  147. 2 rows in set (0.00 sec)  
  148.   
  149. (casystem)root@localhost [(none)]> show full processlist;  
  150. +----+------+-----------+------+---------+------+-------+-----------------------+  
  151. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  152. +----+------+-----------+------+---------+------+-------+-----------------------+  
  153. |  7 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  154. +----+------+-----------+------+---------+------+-------+-----------------------+  
  155. 1 row in set (0.01 sec)  



[plain] view plain copy
  1. 3.2 session.wait_timeout>cnf.interactive_timeout时,session.wait_timeout是否会覆盖interactive_timeout?  
  2. set wait_timeout=12;  
  3.   
  4. > set wait_timeout=12;  
  5. Query OK, 0 rows affected (0.00 sec)  
  6.   
  7. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  8. +---------------------------------+-------------------+  
  9. | Variable_name                   | Value             |  
  10. +---------------------------------+-------------------+  
  11. | binlog_max_flush_queue_time     | 0                 |  
  12. | connect_timeout                 | 10                |  
  13. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  14. | delayed_insert_timeout          | 300               |  
  15. | explicit_defaults_for_timestamp | OFF               |  
  16. | flush_time                      | 0                 |  
  17. | innodb_flush_log_at_timeout     | 1                 |  
  18. | innodb_lock_wait_timeout        | 50                |  
  19. | innodb_old_blocks_time          | 1000              |  
  20. | innodb_rollback_on_timeout      | OFF               |  
  21. | interactive_timeout             | 10                |  
  22. | lc_time_names                   | en_US             |  
  23. | lock_wait_timeout               | 31536000          |  
  24. | long_query_time                 | 0.020000          |  
  25. | net_read_timeout                | 30                |  
  26. | net_write_timeout               | 60                |  
  27. | rpl_stop_slave_timeout          | 31536000          |  
  28. | slave_net_timeout               | 3600              |  
  29. | slow_launch_time                | 2                 |  
  30. | system_time_zone                | CST               |  
  31. | time_format                     | %H:%i:%s          |  
  32. | time_zone                       | SYSTEM            |  
  33. | timed_mutexes                   | OFF               |  
  34. | timestamp                       | 1442820744.921596 |  
  35. | wait_timeout                    | 12                |  
  36. +---------------------------------+-------------------+  
  37. 25 rows in set (0.00 sec)  
  38.   
  39. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  40. +---------------------------------+-------------------+  
  41. | Variable_name                   | Value             |  
  42. +---------------------------------+-------------------+  
  43. | binlog_max_flush_queue_time     | 0                 |  
  44. | connect_timeout                 | 10                |  
  45. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  46. | delayed_insert_timeout          | 300               |  
  47. | explicit_defaults_for_timestamp | OFF               |  
  48. | flush_time                      | 0                 |  
  49. | innodb_flush_log_at_timeout     | 1                 |  
  50. | innodb_lock_wait_timeout        | 50                |  
  51. | innodb_old_blocks_time          | 1000              |  
  52. | innodb_rollback_on_timeout      | OFF               |  
  53. | interactive_timeout             | 10                |  
  54. | lc_time_names                   | en_US             |  
  55. | lock_wait_timeout               | 31536000          |  
  56. | long_query_time                 | 0.020000          |  
  57. | net_read_timeout                | 30                |  
  58. | net_write_timeout               | 60                |  
  59. | rpl_stop_slave_timeout          | 31536000          |  
  60. | slave_net_timeout               | 3600              |  
  61. | slow_launch_time                | 2                 |  
  62. | system_time_zone                | CST               |  
  63. | time_format                     | %H:%i:%s          |  
  64. | time_zone                       | SYSTEM            |  
  65. | timed_mutexes                   | OFF               |  
  66. | wait_timeout                    | 15                |  
  67. +---------------------------------+-------------------+  
  68. 24 rows in set (0.00 sec)  
  69.   
  70. 当前会话超时时间---超时时间是wait_timeout=12秒,不是10秒,修改当前会话的wait_timeout,没有覆盖interactive_timeout,但是起作用的是wait_timeout  
  71. > show full processlist;  
  72. +----+------+-----------+------+---------+------+-------+-----------------------+  
  73. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  74. +----+------+-----------+------+---------+------+-------+-----------------------+  
  75. |  8 | ca   | localhost | NULL | Sleep   |   12 |       | NULL                  |  
  76. |  9 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  77. +----+------+-----------+------+---------+------+-------+-----------------------+  
  78. 2 rows in set (0.00 sec)  
  79.   
  80. (casystem)root@localhost [(none)]> show full processlist;  
  81. +----+------+-----------+------+---------+------+-------+-----------------------+  
  82. | Id | User | Host      | db   | Command | Time | State | Info                  |  
  83. +----+------+-----------+------+---------+------+-------+-----------------------+  
  84. |  9 | root | localhost | NULL | Query   |    0 | init  | show full processlist |  
  85. +----+------+-----------+------+---------+------+-------+-----------------------+  
  86. 1 row in set (0.00 sec)  


[plain] view plain copy
  1. 3.3 global.wait_timeout<cnf.interactive_timeout时,global.wait_timeout是否会覆盖interactive_timeout?  
  2. set global wait_timeout=8;  
  3.   
  4. 当前会话---当前会话的超时时间是10,并未修改成8,当前会话超时之后,也没有修改成8.(原因,实验1,以interactive_timeout为准)  
  5. > set global wait_timeout=8;  
  6. Query OK, 0 rows affected (0.00 sec)  
  7.   
  8. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  9. +---------------------------------+-------------------+  
  10. | Variable_name                   | Value             |  
  11. +---------------------------------+-------------------+  
  12. | binlog_max_flush_queue_time     | 0                 |  
  13. | connect_timeout                 | 10                |  
  14. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  15. | delayed_insert_timeout          | 300               |  
  16. | explicit_defaults_for_timestamp | OFF               |  
  17. | flush_time                      | 0                 |  
  18. | innodb_flush_log_at_timeout     | 1                 |  
  19. | innodb_lock_wait_timeout        | 50                |  
  20. | innodb_old_blocks_time          | 1000              |  
  21. | innodb_rollback_on_timeout      | OFF               |  
  22. | interactive_timeout             | 10                |  
  23. | lc_time_names                   | en_US             |  
  24. | lock_wait_timeout               | 31536000          |  
  25. | long_query_time                 | 0.020000          |  
  26. | net_read_timeout                | 30                |  
  27. | net_write_timeout               | 60                |  
  28. | rpl_stop_slave_timeout          | 31536000          |  
  29. | slave_net_timeout               | 3600              |  
  30. | slow_launch_time                | 2                 |  
  31. | system_time_zone                | CST               |  
  32. | time_format                     | %H:%i:%s          |  
  33. | time_zone                       | SYSTEM            |  
  34. | timed_mutexes                   | OFF               |  
  35. | timestamp                       | 1442821194.483634 |  
  36. | wait_timeout                    | 10                |  
  37. +---------------------------------+-------------------+  
  38. 25 rows in set (0.00 sec)  
  39.   
  40. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  41. +---------------------------------+-------------------+  
  42. | Variable_name                   | Value             |  
  43. +---------------------------------+-------------------+  
  44. | binlog_max_flush_queue_time     | 0                 |  
  45. | connect_timeout                 | 10                |  
  46. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  47. | delayed_insert_timeout          | 300               |  
  48. | explicit_defaults_for_timestamp | OFF               |  
  49. | flush_time                      | 0                 |  
  50. | innodb_flush_log_at_timeout     | 1                 |  
  51. | innodb_lock_wait_timeout        | 50                |  
  52. | innodb_old_blocks_time          | 1000              |  
  53. | innodb_rollback_on_timeout      | OFF               |  
  54. | interactive_timeout             | 10                |  
  55. | lc_time_names                   | en_US             |  
  56. | lock_wait_timeout               | 31536000          |  
  57. | long_query_time                 | 0.020000          |  
  58. | net_read_timeout                | 30                |  
  59. | net_write_timeout               | 60                |  
  60. | rpl_stop_slave_timeout          | 31536000          |  
  61. | slave_net_timeout               | 3600              |  
  62. | slow_launch_time                | 2                 |  
  63. | system_time_zone                | CST               |  
  64. | time_format                     | %H:%i:%s          |  
  65. | time_zone                       | SYSTEM            |  
  66. | timed_mutexes                   | OFF               |  
  67. | wait_timeout                    | 8                 |  
  68. +---------------------------------+-------------------+  
  69. 24 rows in set (0.00 sec)  
  70.   
  71. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  72. ERROR 2006 (HY000): MySQL server has gone away  
  73. No connection. Trying to reconnect...  
  74. Connection id:    12  
  75. Current database: *** NONE ***  
  76.   
  77. +---------------------------------+-------------------+  
  78. | Variable_name                   | Value             |  
  79. +---------------------------------+-------------------+  
  80. | binlog_max_flush_queue_time     | 0                 |  
  81. | connect_timeout                 | 10                |  
  82. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  83. | delayed_insert_timeout          | 300               |  
  84. | explicit_defaults_for_timestamp | OFF               |  
  85. | flush_time                      | 0                 |  
  86. | innodb_flush_log_at_timeout     | 1                 |  
  87. | innodb_lock_wait_timeout        | 50                |  
  88. | innodb_old_blocks_time          | 1000              |  
  89. | innodb_rollback_on_timeout      | OFF               |  
  90. | interactive_timeout             | 10                |  
  91. | lc_time_names                   | en_US             |  
  92. | lock_wait_timeout               | 31536000          |  
  93. | long_query_time                 | 0.020000          |  
  94. | net_read_timeout                | 30                |  
  95. | net_write_timeout               | 60                |  
  96. | rpl_stop_slave_timeout          | 31536000          |  
  97. | slave_net_timeout               | 3600              |  
  98. | slow_launch_time                | 2                 |  
  99. | system_time_zone                | CST               |  
  100. | time_format                     | %H:%i:%s          |  
  101. | time_zone                       | SYSTEM            |  
  102. | timed_mutexes                   | OFF               |  
  103. | timestamp                       | 1442821244.086780 |  
  104. | wait_timeout                    | 10                |  
  105. +---------------------------------+-------------------+  
  106. 25 rows in set (0.00 sec)  
  107.   
  108. 新会话--新会话的超时时间,未修改8秒。 (原因,实验1,以interactive_timeout为准)  
  109. > show  variables like '%time%';  
  110. +---------------------------------+-------------------+  
  111. | Variable_name                   | Value             |  
  112. +---------------------------------+-------------------+  
  113. | binlog_max_flush_queue_time     | 0                 |  
  114. | connect_timeout                 | 10                |  
  115. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  116. | delayed_insert_timeout          | 300               |  
  117. | explicit_defaults_for_timestamp | OFF               |  
  118. | flush_time                      | 0                 |  
  119. | innodb_flush_log_at_timeout     | 1                 |  
  120. | innodb_lock_wait_timeout        | 50                |  
  121. | innodb_old_blocks_time          | 1000              |  
  122. | innodb_rollback_on_timeout      | OFF               |  
  123. | interactive_timeout             | 10                |  
  124. | lc_time_names                   | en_US             |  
  125. | lock_wait_timeout               | 31536000          |  
  126. | long_query_time                 | 0.020000          |  
  127. | net_read_timeout                | 30                |  
  128. | net_write_timeout               | 60                |  
  129. | rpl_stop_slave_timeout          | 31536000          |  
  130. | slave_net_timeout               | 3600              |  
  131. | slow_launch_time                | 2                 |  
  132. | system_time_zone                | CST               |  
  133. | time_format                     | %H:%i:%s          |  
  134. | time_zone                       | SYSTEM            |  
  135. | timed_mutexes                   | OFF               |  
  136. | timestamp                       | 1442821214.497556 |  
  137. | wait_timeout                    | 10                |  
  138. +---------------------------------+-------------------+  
  139. 25 rows in set (0.00 sec)  
  140.   
  141. (casystem)ca@localhost [(none)]> show global variables like '%time%';  
  142. +---------------------------------+-------------------+  
  143. | Variable_name                   | Value             |  
  144. +---------------------------------+-------------------+  
  145. | binlog_max_flush_queue_time     | 0                 |  
  146. | connect_timeout                 | 10                |  
  147. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  148. | delayed_insert_timeout          | 300               |  
  149. | explicit_defaults_for_timestamp | OFF               |  
  150. | flush_time                      | 0                 |  
  151. | innodb_flush_log_at_timeout     | 1                 |  
  152. | innodb_lock_wait_timeout        | 50                |  
  153. | innodb_old_blocks_time          | 1000              |  
  154. | innodb_rollback_on_timeout      | OFF               |  
  155. | interactive_timeout             | 10                |  
  156. | lc_time_names                   | en_US             |  
  157. | lock_wait_timeout               | 31536000          |  
  158. | long_query_time                 | 0.020000          |  
  159. | net_read_timeout                | 30                |  
  160. | net_write_timeout               | 60                |  
  161. | rpl_stop_slave_timeout          | 31536000          |  
  162. | slave_net_timeout               | 3600              |  
  163. | slow_launch_time                | 2                 |  
  164. | system_time_zone                | CST               |  
  165. | time_format                     | %H:%i:%s          |  
  166. | time_zone                       | SYSTEM            |  
  167. | timed_mutexes                   | OFF               |  
  168. | wait_timeout                    | 8                 |  
  169. +---------------------------------+-------------------+  
  170. 24 rows in set (0.00 sec)  



[plain] view plain copy
  1. 3.4 global.wait_timeout>cnf.interactive_timeout时,global.wait_timeout是否会覆盖interactive_timeout?  
  2. set global wait_timeout=12;  
  3.   
  4. 当前会话---当前会话超时时间并未修改成12秒,而且超时之后也没有修改成12秒 (原因,实验1,以interactive_timeout为准)  
  5. > set global wait_timeout=12;  
  6. Query OK, 0 rows affected (0.00 sec)  
  7.   
  8. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  9. +---------------------------------+-------------------+  
  10. | Variable_name                   | Value             |  
  11. +---------------------------------+-------------------+  
  12. | binlog_max_flush_queue_time     | 0                 |  
  13. | connect_timeout                 | 10                |  
  14. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  15. | delayed_insert_timeout          | 300               |  
  16. | explicit_defaults_for_timestamp | OFF               |  
  17. | flush_time                      | 0                 |  
  18. | innodb_flush_log_at_timeout     | 1                 |  
  19. | innodb_lock_wait_timeout        | 50                |  
  20. | innodb_old_blocks_time          | 1000              |  
  21. | innodb_rollback_on_timeout      | OFF               |  
  22. | interactive_timeout             | 10                |  
  23. | lc_time_names                   | en_US             |  
  24. | lock_wait_timeout               | 31536000          |  
  25. | long_query_time                 | 0.020000          |  
  26. | net_read_timeout                | 30                |  
  27. | net_write_timeout               | 60                |  
  28. | rpl_stop_slave_timeout          | 31536000          |  
  29. | slave_net_timeout               | 3600              |  
  30. | slow_launch_time                | 2                 |  
  31. | system_time_zone                | CST               |  
  32. | time_format                     | %H:%i:%s          |  
  33. | time_zone                       | SYSTEM            |  
  34. | timed_mutexes                   | OFF               |  
  35. | timestamp                       | 1442821797.229564 |  
  36. | wait_timeout                    | 10                |  
  37. +---------------------------------+-------------------+  
  38. 25 rows in set (0.00 sec)  
  39.   
  40. (casystem)ca@localhost [(none)]>  show global variables like '%time%';  
  41. +---------------------------------+-------------------+  
  42. | Variable_name                   | Value             |  
  43. +---------------------------------+-------------------+  
  44. | binlog_max_flush_queue_time     | 0                 |  
  45. | connect_timeout                 | 10                |  
  46. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  47. | delayed_insert_timeout          | 300               |  
  48. | explicit_defaults_for_timestamp | OFF               |  
  49. | flush_time                      | 0                 |  
  50. | innodb_flush_log_at_timeout     | 1                 |  
  51. | innodb_lock_wait_timeout        | 50                |  
  52. | innodb_old_blocks_time          | 1000              |  
  53. | innodb_rollback_on_timeout      | OFF               |  
  54. | interactive_timeout             | 10                |  
  55. | lc_time_names                   | en_US             |  
  56. | lock_wait_timeout               | 31536000          |  
  57. | long_query_time                 | 0.020000          |  
  58. | net_read_timeout                | 30                |  
  59. | net_write_timeout               | 60                |  
  60. | rpl_stop_slave_timeout          | 31536000          |  
  61. | slave_net_timeout               | 3600              |  
  62. | slow_launch_time                | 2                 |  
  63. | system_time_zone                | CST               |  
  64. | time_format                     | %H:%i:%s          |  
  65. | time_zone                       | SYSTEM            |  
  66. | timed_mutexes                   | OFF               |  
  67. | wait_timeout                    | 12                |  
  68. +---------------------------------+-------------------+  
  69. 24 rows in set (0.00 sec)  
  70.   
  71. (casystem)ca@localhost [(none)]>  show  variables like '%time%';  
  72. ERROR 2006 (HY000): MySQL server has gone away  
  73. No connection. Trying to reconnect...  
  74. Connection id:    19  
  75. Current database: *** NONE ***  
  76.   
  77. +---------------------------------+-------------------+  
  78. | Variable_name                   | Value             |  
  79. +---------------------------------+-------------------+  
  80. | binlog_max_flush_queue_time     | 0                 |  
  81. | connect_timeout                 | 10                |  
  82. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  83. | delayed_insert_timeout          | 300               |  
  84. | explicit_defaults_for_timestamp | OFF               |  
  85. | flush_time                      | 0                 |  
  86. | innodb_flush_log_at_timeout     | 1                 |  
  87. | innodb_lock_wait_timeout        | 50                |  
  88. | innodb_old_blocks_time          | 1000              |  
  89. | innodb_rollback_on_timeout      | OFF               |  
  90. | interactive_timeout             | 10                |  
  91. | lc_time_names                   | en_US             |  
  92. | lock_wait_timeout               | 31536000          |  
  93. | long_query_time                 | 0.020000          |  
  94. | net_read_timeout                | 30                |  
  95. | net_write_timeout               | 60                |  
  96. | rpl_stop_slave_timeout          | 31536000          |  
  97. | slave_net_timeout               | 3600              |  
  98. | slow_launch_time                | 2                 |  
  99. | system_time_zone                | CST               |  
  100. | time_format                     | %H:%i:%s          |  
  101. | time_zone                       | SYSTEM            |  
  102. | timed_mutexes                   | OFF               |  
  103. | timestamp                       | 1442821862.560630 |  
  104. | wait_timeout                    | 10                |  
  105. +---------------------------------+-------------------+  
  106. 25 rows in set (0.00 sec)  
  107.   
  108. 新会话 -- 新会话的超时时间,未修改12秒。 (原因,实验1,以interactive_timeout为准)  
  109. > show global variables like '%time%';  
  110. +---------------------------------+-------------------+  
  111. | Variable_name                   | Value             |  
  112. +---------------------------------+-------------------+  
  113. | binlog_max_flush_queue_time     | 0                 |  
  114. | connect_timeout                 | 10                |  
  115. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  116. | delayed_insert_timeout          | 300               |  
  117. | explicit_defaults_for_timestamp | OFF               |  
  118. | flush_time                      | 0                 |  
  119. | innodb_flush_log_at_timeout     | 1                 |  
  120. | innodb_lock_wait_timeout        | 50                |  
  121. | innodb_old_blocks_time          | 1000              |  
  122. | innodb_rollback_on_timeout      | OFF               |  
  123. | interactive_timeout             | 10                |  
  124. | lc_time_names                   | en_US             |  
  125. | lock_wait_timeout               | 31536000          |  
  126. | long_query_time                 | 0.020000          |  
  127. | net_read_timeout                | 30                |  
  128. | net_write_timeout               | 60                |  
  129. | rpl_stop_slave_timeout          | 31536000          |  
  130. | slave_net_timeout               | 3600              |  
  131. | slow_launch_time                | 2                 |  
  132. | system_time_zone                | CST               |  
  133. | time_format                     | %H:%i:%s          |  
  134. | time_zone                       | SYSTEM            |  
  135. | timed_mutexes                   | OFF               |  
  136. | wait_timeout                    | 12                |  
  137. +---------------------------------+-------------------+  
  138. 24 rows in set (0.00 sec)  
  139.   
  140. (casystem)ca@localhost [(none)]> show  variables like '%time%';  
  141. +---------------------------------+-------------------+  
  142. | Variable_name                   | Value             |  
  143. +---------------------------------+-------------------+  
  144. | binlog_max_flush_queue_time     | 0                 |  
  145. | connect_timeout                 | 10                |  
  146. | datetime_format                 | %Y-%m-%d %H:%i:%s |  
  147. | delayed_insert_timeout          | 300               |  
  148. | explicit_defaults_for_timestamp | OFF               |  
  149. | flush_time                      | 0                 |  
  150. | innodb_flush_log_at_timeout     | 1                 |  
  151. | innodb_lock_wait_timeout        | 50                |  
  152. | innodb_old_blocks_time          | 1000              |  
  153. | innodb_rollback_on_timeout      | OFF               |  
  154. | interactive_timeout             | 10                |  
  155. | lc_time_names                   | en_US             |  
  156. | lock_wait_timeout               | 31536000          |  
  157. | long_query_time                 | 0.020000          |  
  158. | net_read_timeout                | 30                |  
  159. | net_write_timeout               | 60                |  
  160. | rpl_stop_slave_timeout          | 31536000          |  
  161. | slave_net_timeout               | 3600              |  
  162. | slow_launch_time                | 2                 |  
  163. | system_time_zone                | CST               |  
  164. | time_format                     | %H:%i:%s          |  
  165. | time_zone                       | SYSTEM            |  
  166. | timed_mutexes                   | OFF               |  
  167. | timestamp                       | 1442821846.568606 |  
  168. | wait_timeout                    | 10                |  
  169. +---------------------------------+-------------------+  
  170. 25 rows in set (0.00 sec)  
  171.   
  172. (casystem)ca@localhost [(none)]>   







About Me

.............................................................................................................................................

● 本文作者:小麦苗,部分内容整理自网络,若有侵权请联系小麦苗删除

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、博客园(http://www.cnblogs.com/lhrbest)和个人微信公众号(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文博客园地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、个人简介及小麦苗云盘地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 数据库笔试面试题库及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA宝典今日头条号地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群号:230161599(满)、618766405

● 微信群:可加我微信,我拉大家进群,非诚勿扰

● 联系我请加QQ好友646634621,注明添加缘由

● 于 2017-12-01 09:00 ~ 2017-12-31 22:00 在魔都完成

● 文章内容来源于小麦苗的学习笔记,部分整理自网络,若有侵权或不当之处还请谅解

● 版权所有,欢迎分享本文,转载请保留出处

.............................................................................................................................................

小麦苗的微店:https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麦苗出版的数据库类丛书:http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客户端扫描下面的二维码来关注小麦苗的微信公众号(xiaomaimiaolhr)及QQ群(DBA宝典),学习最实用的数据库技术。

【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?

   小麦苗的微信公众号      小麦苗的DBA宝典QQ群2     《DBA笔试面宝典》读者群       小麦苗的微店

.............................................................................................................................................

【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?
【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么? 【MySQL】参数wait_timeout和interactive_timeout的作用和区别是什么?




###wait_timeout interactive_timeout####

wait_timeout :对于非交互连接,mysql在关闭它之前的等待时间
              这个值的初始化根据连接客户端的连接方式不同:有两种方式:全局的wait_timeout或者是全局的interactive_timeout

interactive_timeout:对于交互连接,mysql在关闭它之前的等待时间

测试:
root:3406:(none)>show variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 21       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

root:3406:(none)>show global variables like '%timeout%';
+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 14       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

root:3406:(none)>show global variables like '%timeout%';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id:    4
Current database: *** NONE ***

+-----------------------------+----------+
| Variable_name               | Value    |
+-----------------------------+----------+
| connect_timeout             | 10       |
| delayed_insert_timeout      | 300      |
| have_statement_timeout      | YES      |
| innodb_flush_log_at_timeout | 1        |
| innodb_lock_wait_timeout    | 50       |
| innodb_rollback_on_timeout  | OFF      |
| interactive_timeout         | 21       |
| lock_wait_timeout           | 31536000 |
| net_read_timeout            | 30       |
| net_write_timeout           | 60       |
| rpl_stop_slave_timeout      | 31536000 |
| slave_net_timeout           | 60       |
| thread_pool_idle_timeout    | 60       |
| wait_timeout                | 14       |
+-----------------------------+----------+
14 rows in set (0.00 sec)

上面是测试交互输入的方式,
wait_timeout =14
interactive_timeout=21
可以看到session级别的wait_timeout的初始化使用了interactive_timeout
当超过了21s后,再执行命令连接已经被干掉了


综上:
针对client其实真正生效的是session级别的wait_timeout,空闲连接(交互和非交互),
超过其session级别的wait_timeout时间就会被回收掉:
伪代码:
if (client_connection is interactive) then
  session  wait_timeout= global interactive_timeout
else if(client_connection is noninteractive ) then
   session  wait_timeout= global wait_timeout
end if

正文到此结束
Loading...