MySQL wait_timeout Variable - GLOBAL vs SESSION

后端 未结 3 1129
灰色年华
灰色年华 2020-12-07 16:46
SHOW VARIABLES LIKE \"%wait%\"

Result: 28800

SET @@GLOBAL.wait_timeout=300

SHOW GLOBAL VARIABLES LIKE \"%wait%\"

Result: 300

SHOW SESSION VARIABLES LIKE \"%wait         


        
3条回答
  •  暖寄归人
    2020-12-07 17:04

    SHOW SESSION VARIABLES LIKE "wait_timeout"; -- 28800
    SHOW GLOBAL VARIABLES LIKE "wait_timeout"; -- 28800
    

    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.

    SET @@GLOBAL.wait_timeout=300
    

    After you set the global variable, the session variable automatically grabs the value.

    SHOW SESSION VARIABLES LIKE "wait_timeout"; -- 300
    SHOW GLOBAL VARIABLES LIKE "wait_timeout"; -- 300
    

    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

提交回复
热议问题