Viewing System Variables

Do not write session, default local variable

Look at all

show variables;
show session variables;
show global variables;
Copy the code

Search keywords

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%';
Copy the code

Look at the individual

select @@autocommit;
select @@session.autocommit;
select @@global.autocommit;
Copy the code

Modifying system Variables

Do not write session default local variables

set @@autocommit = 0;
set @@session.autocommit = 0;
set @@global.autocommit = 0;

set autocommit = 0;
set session autocommit = 0;
set global autocommit = 0;
Copy the code

The difference between system variables and user variables

  • System variables are built-in to mysql and can be used without declaration
  • Users can define their own variables, need to be declared to use

Create user variables

Global user variable (valid for current session)

set @hello = 1;
select @hello;
Copy the code

Global local variable (begin endThe effective)

create procedure test(a)begin   
  declare x int default = 0;
  select x;
end;
Copy the code

Quick jump

  • [MySQL speed of Light]015 talk about stored procedures
  • [MySQL]017 “Exception handling” in a stored procedure