MySQL连接超时相关的两个参数interactive

39次阅读
没有评论

共计 1837 个字符,预计需要花费 5 分钟才能阅读完成。

行业资讯    
数据库    
MySQL 数据库    
MySQL 连接超时相关的两个参数 interactive_timeout 和 wait_timeout 的区别及解释

本篇内容主要讲解“MySQL 连接超时相关的两个参数 interactive_timeout 和 wait_timeout 的区别及解释”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“MySQL 连接超时相关的两个参数 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.

interactive_timeout 针对交互式连接,wait_timeout 针对非交互式连接。所谓的交互式连接,即在 mysql_real_connect() 函数中使用了 CLIENT_INTERACTIVE 选项。
说得直白一点,通过 mysql 客户端连接数据库是交互式连接,通过 jdbc 连接数据库是非交互式连接。 

interactive_timeout:交互式连接超时时间 (mysql 工具、mysqldump 等)
wait_timeout:非交互式连接超时时间,默认的连接 mysql api 程序,jdbc 连接数据库等
  在连接启动的时候,根据连接的类型,来确认会话变量 wait_timeout 的值是继承于全局变量 wait_timeout,还是 interactive_timeout。

如何设置和查看:
mysql set global interactive_timeout=1800;
Query OK, 0 rows affected (0.00 sec)

mysql set global wait_timeout=1800;
Query OK, 0 rows affected (0.00 sec)

mysql show global variables like interactive_timeout
+———————+——-+
| Variable_name       | Value |
+———————+——-+
| interactive_timeout | 1800  |
+———————+——-+
1 row in set (0.00 sec)

mysql show global variables like wait_timeout
+—————+——-+
| Variable_name | Value |
+—————+——-+
| wait_timeout  | 1800  |
+—————+——-+
1 row in set (0.00 sec)

到此,相信大家对“MySQL 连接超时相关的两个参数 interactive_timeout 和 wait_timeout 的区别及解释”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-01发表,共计1837字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)