Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL wait_timeout Variable - GLOBAL vs 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 

I am confused by the results. Why does the last query give Result:28800 ?

like image 969
Arunjith Avatar asked Dec 14 '10 14:12

Arunjith


People also ask

What is the default Wait_timeout in MySQL?

MySQL has its wait_timeout variable default value set to 28800 seconds (8 hours).

How to see wait_ timeout in MySQL?

To run these commands, first we need to login to MySql server. We can check the current values of the wait_timeout variable using below commands. SHOW SESSION VARIABLES LIKE “%wait_timeout%”; or SHOW SESSION VARIABLES LIKE “wait_timeout”; Default wait_timeout value is 28800 seconds.

What is Session variable in MySQL?

A session variable is a user-defined variable (not a server option) that starts with @, does not require declaration, can be used in any SQL query or statement, not visible to other sessions, and exists until the end of the current session.


1 Answers

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 see

SHOW SESSION VARIABLES LIKE "%wait%";  Result: 300 

Similarly, at any time, if you did

mysql> SET session wait_timeout=300; 

You'd get

mysql> SHOW SESSION VARIABLES LIKE 'wait_timeout';  +---------------+-------+ | Variable_name | Value | +---------------+-------+ | wait_timeout  | 300   | +---------------+-------+ 
like image 109
Riedsio Avatar answered Oct 07 '22 17:10

Riedsio