MySQL 为什么我无法在运行时更改变量 long_query_time 变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15541603/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why I could not alter the variable long_query_time variable at runtime
提问by neotam
I am using MySQL version 5.1.66. I saw that the long_query_timevariable is dynamic, but when I tried
我使用的是 MySQL 5.1.66 版。我看到long_query_time变量是动态的,但是当我尝试
set GLOBAL long_query_time=1;
After the above operation again I tried
再次进行上述操作后,我尝试了
mysql> show variables like 'long_query_time';
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.00 sec)
From the mysql console it is not getting altered , why?
从 mysql 控制台它没有被改变,为什么?
回答by geertjanvdk
You are setting a GLOBAL system variable, but you querying for the SESSION variable. For the GLOBAL variable setting to take effect for the current session, you need to reconnect, or set the @@SESSION.long_query_time variable. (Note that SHOW VARIABLES by default shows the session variables.)
您正在设置 GLOBAL 系统变量,但您查询的是 SESSION 变量。为了让GLOBAL变量设置对当前会话生效,需要重新连接,或者设置@@SESSION.long_query_time变量。(请注意,默认情况下 SHOW VARIABLES 显示会话变量。)
Here is an example:
下面是一个例子:
mysql> SHOW SESSION VARIABLES LIKE "long_query_time";
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
mysql> SET @@GLOBAL.long_query_time = 1;
mysql> SHOW GLOBAL VARIABLES LIKE "long_query_time";
+-----------------+----------+
| Variable_name | Value |
+-----------------+----------+
| long_query_time | 1.000000 |
+-----------------+----------+
mysql> SHOW VARIABLES LIKE "long_query_time";
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
MySQL 8.0 introduced the SET PERSIST ..
syntax which could help persist configuration you are setting dynamically. See the MySQL 8.0 manual
MySQL 8.0 引入了SET PERSIST ..
可以帮助持久化您动态设置的配置的语法。请参阅MySQL 8.0 手册
回答by shola
Changing a system variable value in mysql (cfr. http://dev.mysql.com/doc/refman/5.1/en/set-statement.html) does not alter the value for clients already connected to a session.
更改 mysql 中的系统变量值(参见http://dev.mysql.com/doc/refman/5.1/en/set-statement.html)不会更改已连接到会话的客户端的值。
The change will last until server reboot, subsequent changes or session expiration.
更改将持续到服务器重新启动、后续更改或会话到期。
please refer http://bugs.mysql.com/bug.php?id=38704for more details