[MySQL光速入门]016 图解变量

933 阅读1分钟

变量.png

查看系统变量

不写session, 默认局部变量

变量.png

查看全部

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;

修改变量.png

修改系统变量

不写session 默认 局部变量

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

set autocommit = 0;
set session autocommit = 0;
set global autocommit = 0;

系统变量和用户变量的区别

系统变量.png

用户变量.png

  • 系统变量是mysql自带的, 不用声明即可使用, 当然也不能新增
  • 用户可以自己定义的变量, 需要声明才能使用

创建用户变量

全局用户变量(当前会话有效)

set @hello = 1;
select @hello;

全局局部变量(begin end中有效)

创建用户局部变量.png

create procedure test() begin   
  declare x int default = 0;
  select x;
end;

快速跳转