在一次修改MySQL5.7 wait_timeout变量的时候,配置文件增加wait_timeout = 57600参数后,发现一个非常有意思的现象,如下:
(1)查看session级别wait_timeout值没有变化,还是默认28800s
MySQL [(none)]> show variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 28800 |
+---------------+-------+
1 row in set (0.00 sec)
(2)查看global级别wait_timeout值已经改变,57600s
MySQL [(none)]> show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout | 57600 |
+---------------+-------+
1 row in set (0.00 sec)
【注】wait_timeout参数值是程序和数据库的交互等待时间,默认是8个小时,如果等待的时间设置太长也会耗费过多资源。
为了搞明白这个奇怪的问题,我就去翻了翻MySQL官网:https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html
(1)wait_timeout
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
.
译:在线程启动时,会话 wait_timeout值是从全局wait_timeout值还是从全局 interactive_timeout值初始化 ,具体取决于客户端的类型。由此可见,在客户端配置未知的情况下,session级别wait_timeout值受global wait_timeout值和global interactive_timeout值两个变量影响。
(2)interactive_timeout
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
.
(1)持久化—修改配置文件
[root@ansible ~]# vim /etc/my.cnf
[mysqld]
wait_timeout = 57600
interactive_timeout = 57600
(2)临时修改
MySQL [(none)]> set global wait_timeout = 57600;
MySQL [(none)]> set wait_timeout = 57600;
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。