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 ?
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
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
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 themysql
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