
檢視系統變數
不寫
session
, 預設區域性變數

檢視全部
show variables;
show session variables;
show global variables;
複製程式碼
搜尋關鍵字
show variables like 'auto%';
show variables like 'auto%';
show session variables like 'auto%';
show session variables like 'auto%';
show global variables like 'auto%';
show global variables like 'auto%';
複製程式碼
檢視單個
select @@autocommit;
select @@session.autocommit;
select @@global.autocommit;
複製程式碼

修改系統變數
不寫
session
預設 區域性變數
set @@autocommit = 0;
set @@session.autocommit = 0;
set @@global.autocommit = 0;
set autocommit = 0;
set session autocommit = 0;
set global autocommit = 0;
複製程式碼
系統變數和使用者變數的區別


- 系統變數是mysql自帶的, 不用宣告即可使用, 當然也不能新增
- 使用者可以自己定義的變數, 需要宣告才能使用
建立使用者變數
全域性使用者變數(當前會話有效)
set @hello = 1;
select @hello;
複製程式碼
全域性區域性變數(begin end
中有效)

create procedure test() begin
declare x int default = 0;
select x;
end;
複製程式碼