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

变量.png

查看系统变量

不写session, 默认局部变量mysql

变量.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 默认 局部变量sql

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;
复制代码

快速跳转

相关文章
相关标签/搜索