MySQL wait_timeout 全局和会话设置问题

MySQL wait_timeout global and session setting issue

在MySQL中,一些参数有两个值:

1) 会话。
2) 对于全局。

我们可以检查以下参数的值:

1) 显示像 'wait_timeout'
这样的变量 2) 显示全局变量,如 'wait_timeout'

现在 returns 值:
1) 会话 = 500
2) 对于全局 = 28800

我可以通过命令更改变量:
设置全局 wait_timeout=100 ;
设置会话 wait_timeout= 200;

但是当我再次登录时,我得到以下值:
会话 = 500
对于全局 = 100.

意思是全局值保留,会话不保留,完全正确。 但我担心的是我们如何才能更改所有会话的会话变量? 因为在这种情况下全局不是每个会话所采用的值。

是的,

MySQL 中有 2 次超时。您的连接采用哪一个取决于连接类型。一个用于 BATCH 处理,另一个用于交互

第二个变量是interactive_timeout。

看看interactive_timeout

的设置
SHOW VARIABLES LIKE 'interactive_timeout';
SHOW GLOBAL VARIABLES LIKE 'interactive_timeout';

通过 mysql 客户端登录示例

# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 106426
Server version: 10.1.10-MariaDB-log Homebrew

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 500   |
+---------------+-------+
1 row in set (0.00 sec)

MariaDB [(none)]> show global variables like 'wait_timeout';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 28800 |
+---------------+-------+
1 row in set (0.00 sec)

MariaDB [(none)]> show variables like 'interactive_timeout';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| interactive_timeout | 500   |
+---------------------+-------+
1 row in set (0.01 sec)

MariaDB [(none)]> show global variables like 'interactive_timeout';
+---------------------+-------+
| Variable_name       | Value |
+---------------------+-------+
| interactive_timeout | 500   |
+---------------------+-------+
1 row in set (0.00 sec)

MariaDB [(none)]>

现在在批处理模式下相同

# mysql -uroot -p -e "show variables like 'wait_timeout';"
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 28800 |
+---------------+-------+
#

我得到了准确的描述:

线程启动时,会话 wait_timeout 值从全局 wait_timeout 值或全局 interactive_timeout 值初始化,具体取决于客户端类型(由CLIENT_INTERACTIVE 将选项连接到 mysql_real_connect())

在 MySQL 文档中 wait_timeout description