用户变量

用户变量是会话期的(作用域,生命期)

1
2
3
4
5
6
7
mysql> SET @t1=1, @t2=2, @t3:=4;
mysql> SELECT @t1, @t2, @t3, @t4 := @t1+@t2+@t3;
+------+------+------+--------------------+
| @t1 | @t2 | @t3 | @t4 := @t1+@t2+@t3 |
+------+------+------+--------------------+
| 1 | 2 | 4 | 7 |
+------+------+------+--------------------+

系统变量

  • 查询系统变量

    select @@character_set_server;
    
  • 通过show

    show variables like 'max_allowed_packet';
    

参考

  1. http://dev.mysql.com/doc/refman/5.7/en/user-variables.html
  2. http://dev.mysql.com/doc/refman/5.7/en/set-variable.html
  3. http://dev.mysql.com/doc/refman/5.7/en/show-variables.html
  4. http://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html

留言

2015-11-02