您好,登錄后才能下訂單哦!
標題索引
變量分類
變量設置
變量分類
變量主要分為全局變量和會話變量,全局變量是當客戶端程序與服務器端建立會話后自動集成部分全局變量的值,而會話變量是只對當前變量有效,另外全局變量有些支持在線修改,有些則是只讀變量,只讀變量只允許在配置文件中加載值。
變量設置
1.全局變量設置
全局變量保存在數據庫information_schema的GLOBAL_VARIABLES表中,因此修改時可以通過配置文件加載時修改,部分變量也可通過在線修改,在線修改時通常有兩種命令方式,分別如下:
mysql>SET GLOBAL system_var_name=value;
mysql>SET @@global.system_var_name=value;
舉例說明如下:
MariaDB [(none)]> show global variables like 'transaction_prealloc_size'; +---------------------------+-------+ | Variable_name | Value | +---------------------------+-------+ | transaction_prealloc_size | 4096 | +---------------------------+-------+ 1 row in set (0.00 sec) MariaDB [(none)]> set global transaction_prealloc_size=8192; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show global variables like 'transaction_prealloc_size'; +---------------------------+-------+ | Variable_name | Value | +---------------------------+-------+ | transaction_prealloc_size | 8192 | +---------------------------+-------+ 1 row in set (0.00 sec) MariaDB [(none)]> set @@global.transaction_prealloc_size=4096; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show global variables like 'transaction_prealloc_size'; +---------------------------+-------+ | Variable_name | Value | +---------------------------+-------+ | transaction_prealloc_size | 4096 | +---------------------------+-------+ 1 row in set (0.00 sec)
2.會話變量設置
會話變量保存在數據庫information_schema的SESSION_VARIABLES表中,因此修改時可以通過配置文件加載時修改,部分變量也可通過在線修改,在線修改時通常有兩種命令方式,分別如下:
mysql>SET SESSION system_var_name=value;
mysql>SET @@session.system_var_name=value
MariaDB [(none)]> show session variables like 'wait_timeout'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | wait_timeout | 28800 | +---------------+-------+ 1 row in set (0.00 sec) MariaDB [(none)]> set session wait_timeout=30000; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show session variables like 'wait_timeout'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | wait_timeout | 30000 | +---------------+-------+ 1 row in set (0.00 sec) MariaDB [(none)]> set @@session.wait_timeout=28800; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show session variables like 'wait_timeout'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | wait_timeout | 28800 | +---------------+-------+ 1 row in set (0.00 sec)
3.會話變量轉全局變量
會話變量調整為全局變量時,通常采用如下方法:
mysql> set @@session.wait_timeout=@@global.wait_timeout;
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。