MySQL wait_timeout 变量 - GLOBAL 与 SESSION
SHOW VARIABLES LIKE "%wait%"
Result: 28800
SET @@GLOBAL.wait_timeout=300
SHOW GLOBAL VARIABLES LIKE "%wait%"
Result: 300
SHOW SESSION VARIABLES LIKE "%wait%"
Result:28800
我对结果感到困惑。为什么最后一个查询给出 Result:28800 ?
SHOW VARIABLES LIKE "%wait%"
Result: 28800
SET @@GLOBAL.wait_timeout=300
SHOW GLOBAL VARIABLES LIKE "%wait%"
Result: 300
SHOW SESSION VARIABLES LIKE "%wait%"
Result:28800
I am confused by the results. Why does the last query give Result:28800 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的会话状态在启动会话后设置,并且默认情况下采用当前的 GLOBAL 值。
如果您在执行
SET @@GLOBAL.wait_timeout=300
后断开连接,然后重新连接,您会看到同样,在任何时候,如果您这样做,
您会得到
Your session status are set once you start a session, and by default, take the current GLOBAL value.
If you disconnected after you did
SET @@GLOBAL.wait_timeout=300
, then subsequently reconnected, you'd seeSimilarly, at any time, if you did
You'd get
首先,wait_timeout = 28800,这是默认值。要更改会话值,您需要设置全局变量,因为会话变量是只读的。
设置全局变量后,会话变量会自动获取该值。
下次服务器重新启动时,会话变量将设置为默认值,即28800。PS
我使用MySQL 5.6.16
At first, wait_timeout = 28800 which is the default value. To change the session value, you need to set the global variable because the session variable is read-only.
After you set the global variable, the session variable automatically grabs the value.
Next time when the server restarts, the session variables will be set to the default value i.e. 28800.
P.S. I m using MySQL 5.6.16
正如 Riedsio 所指出的,会话变量在连接后不会更改,除非您专门设置它们;设置全局变量只会更改下一个连接的会话值。
例如,如果您有 100 个连接,并且降低了全局
wait_timeout
,那么它不会影响现有连接,只会影响变量更改后的新连接。不过,特别是对于
wait_timeout
变量,有一个变化。如果您在交互模式下使用
mysql
客户端,或者通过mysql_real_connect()
设置CLIENT_INTERACTIVE
连接器,那么您将看到interactive_timeout
设置为@@session.wait_timeout
在这里您可以看到这一点:
因此,如果您使用客户端对此进行测试,则它是您需要的
interactive_timeout
将在连接时看到,而不是wait_timeout
的值As noted by Riedsio, the session variables do not change after connecting unless you specifically set them; setting the global variable only changes the session value of your next connection.
For example, if you have 100 connections and you lower the global
wait_timeout
then it will not affect the existing connections, only new ones after the variable was changed.Specifically for the
wait_timeout
variable though, there is a twist.If you are using the
mysql
client in the interactive mode, or the connector withCLIENT_INTERACTIVE
set viamysql_real_connect()
then you will see theinteractive_timeout
set for@@session.wait_timeout
Here you can see this demonstrated:
So, if you are testing this using the client it is the
interactive_timeout
that you will see when connecting and not the value ofwait_timeout