变量
# 全局变量
SHOW GLOBAL VARIABLES; # GLOBAL
SHOW VARIABLES; # GLOBAL
SHOW GLOBAL VARIABLES like '%char%';
#不能跨重启
select @@global.autocommit
select @@autocommit
set @@autocommit=1
set SESSION autocommit=1
#会话变量
SHOW SESSION
#用户变量
#声明
set @str='hello';
set @str:='hello2';
select @str:='hello1'
select @str
#赋值
set @str='hello';
set @str:='hello2';
select @str:='hello1'
select 字段 into @变量名 from 表
select @str
# 局部变量
# 声明
DECLARE 变量名 类型;
DECLARE 变量名 类型 DELETE 值;
# 赋值
set 局部变量名='hello';
set 局部变量名:='hello2';
select @局部变量名:='hello1'
select 字段 into 局部变量名 from 表
#查看
select 局部变量名
全局变量,不跨重启,跨会话
系统变量,默认是修饰符是session,局部变量不需要加@,除了搭配select
存储过程
需要定义结束符号
简单案例