MySQL修改wait_timeout变量global生效session不生效
1、背景阐述
在一次修改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个小时,如果等待的时间设置太长也会耗费过多资源。
2、问题分析
为了搞明白这个奇怪的问题,我就去翻了翻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
.
3、解决方案
(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;
作者:UStarGao
链接:https://www.starcto.com/mysql/167.html
来源:STARCTO
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
UCloud云平台推荐
随便看看
- 2021-10-08Redis容器化部署教程
- 2021-02-28Linux账户风险和安全策略
- 2021-09-09开源Wazuh安全平台容器化部署
- 2023-03-12Linux pstree命令树状图方式查看进程
- 2021-01-26容器概念-Docker