您好,登錄后才能下訂單哦!
這篇文章主要講解了“mysql關于variable知識點有哪些”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“mysql關于variable知識點有哪些”吧!
1、MySQL的my.cnf文件類似Oracle的參數文件,可以把它理解成oracle的pfile靜態參數文件
2、MySQL可以使用set命令動態的修改變量,修改session變量只對當前會話產生影響;修改global變量,對所有新會話的global變量、session變量(特殊情況除外,比如wait_timeout變量)產生影響
3、set命令修改的變量不會寫入my.cnf文件,DB重啟的話之前set修改的變量就失效了,想要永久生效,就把變量寫入到my.cnf文件
4、只讀變量,不能使用set修改,只能通過修改my.cnf文件再重啟生效
5、全局(GLOBAL)級變量對整個MySQL服務器有效;會話(SESSION)級變量只影響當前會話。有些變量同時擁有這兩個級別,MySQL將在建立連接時用全局級變量初始化會話級變量,但一旦連接建立之后,全局級變量的改變不會影響到會話級變量
6、可以把全局(GLOBAL)級變量理解成oracle的system參數,會話(SESSION)級變量理解成oracle的session參數
7、mysql沒有類似oracle的create pfile from memory保存所有內存的中參數值的功能,mysql如果要保存所有修改的參數但是沒有寫入my.cnf的方法,就是select * from INFORMATION_SCHEMA.GLOBAL_VARIABLES查詢出來并保存
查看系統變量的值
方法1
mysql> show variables like '%wait_timeout%';
mysql> show global variables like '%wait_timeout%';
mysql> show session variables like '%wait_timeout%';
注意:show variables優先顯示會話級變量的值,如果這個值不存在,則顯示全局級變量的值,當然你也可以加上SESSION關鍵字區別
方法2
mysql> set global show_compatibility_56=on;
mysql> select * from INFORMATION_SCHEMA.GLOBAL_VARIABLES where variable_name like '%wait_timeout%'
mysql> select * from INFORMATION_SCHEMA.SESSION_VARIABLES where variable_name like '%wait_timeout%'
修改系統變量的值
mysql> set wait_timeout = xxx;
mysql> set global wait_timeout = yyy;
只讀系統標量,不能使用set修改
mysql> show variables like 'log_bin';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin | ON |
+---------------+-------+
1 row in set (0.00 sec)
mysql> set log_bin=off;
ERROR 1238 (HY000): Variable 'log_bin' is a read only variable
只有全局變量,沒有會話變量
全局變量修改的時候,其他新開會話的會話變量和全局變量都是修改后的值
會話1
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
mysql> set server_id=2;
ERROR 1229 (HY000): Variable 'server_id' is a GLOBAL variable and should be set with SET GLOBAL
mysql> set GLOBAL server_id=2;
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
mysql> show global variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
打開另一個會話
全局變量修改的時候,其他新開會話的會話變量和全局變量都是修改后的值
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
mysql> show global variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 2 |
+---------------+-------+
有全局變量,也有會話變量
會話變量修改的時候,不影響本身的全局變量,也不影響其他新開會話的會話變量和全局變量
全局變量修改的時候,其他新開會話的會話變量和全局變量都是修改后的值
會話1
mysql> show variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 131072 |
+------------------+--------+
mysql> show global variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 131072 |
+------------------+--------+
mysql> set read_buffer_size=212992;
mysql> show variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 212992 |
+------------------+--------+
mysql> show global variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 131072 |
+------------------+--------+
打開另一個會話2
會話變量修改的時候,不影響本身的全局變量,也不影響其他新開會話的會話變量和全局變量
mysql> show variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 131072 |
+------------------+--------+
mysql> show global variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 131072 |
+------------------+--------+
會話1繼續如下
mysql> set global read_buffer_size=16384;
mysql> show variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 212992 |
+------------------+--------+
mysql> show global variables like 'read_buffer_size';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| read_buffer_size | 16384 |
+------------------+-------+
打開另一個會話3
全局變量修改的時候,其他新開會話的會話變量和全局變量都是修改后的值
mysql> show variables like 'read_buffer_size';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| read_buffer_size | 16384 |
+------------------+-------+
mysql> show global variables like 'read_buffer_size';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| read_buffer_size | 16384 |
+------------------+-------+
重啟之后
重啟之后,所有的set修改的變量值都不在了,回到了初始值
mysql> show variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
mysql> show global variables like 'server_id';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 1 |
+---------------+-------+
mysql> show variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 131072 |
+------------------+--------+
mysql> show global variables like 'read_buffer_size';
+------------------+--------+
| Variable_name | Value |
+------------------+--------+
| read_buffer_size | 131072 |
+------------------+--------+
感謝各位的閱讀,以上就是“mysql關于variable知識點有哪些”的內容了,經過本文的學習后,相信大家對mysql關于variable知識點有哪些這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。