简体   繁体   English

MySQL,@@是什么意思?

[英]MySQL, what does @@ mean?

I am reading the MySQL documentation, on this page http://dev.mysql.com/doc/refman/5.1/en/set-statement.html it often uses "@@", but does not define what "@@" means? 我正在阅读MySQL文档,在此页面上http://dev.mysql.com/doc/refman/5.1/en/set-statement.html它经常使用“ @@”,但未定义“ @@”手段?

Another example is in variable names 另一个例子是变量名

mysql> select @@hostname;
+------------+
| @@hostname |
+------------+
| server1    |
+------------+
1 row in set (0.00 sec)

mysql> select @hostname;
+-----------+
| @hostname |
+-----------+
| NULL      |
+-----------+
1 row in set (0.00 sec)

What is @ vs @@? 什么是@ vs @@?

@@ - System Vaiable @@-系统可用

@@ is used for system variables. @@用于系统变量。 Using different suffix with @@, you can get either session or global value of the system variable. 将不同的后缀与@@一起使用,您可以获取会话或系统变量的全局值。

When you refer to a system variable in an expression as @@var_name (that is, when you do not specify @@global. or @@session.), MySQL returns the session value if it exists and the global value otherwise. 当在表达式中将系统变量称为@@ var_name时(即,当您不指定@@ global。或@@ session。时),MySQL将返回会话值(如果存在),否则返回全局值。 (This differs from SET @@var_name = value, which always refers to the session value.) (这与SET @@ var_name = value不同,后者始终引用会话值。)

@ - User Defined Variable @-用户定义的变量

while @ is used for user defined variables. 而@用于用户定义的变量。

More Details 更多细节

There are more details given to it on the link - http://dev.mysql.com/doc/refman/5.1/en/set-statement.html 在链接上有更多详细信息-http://dev.mysql.com/doc/refman/5.1/en/set-statement.html

Using System Variables : 使用系统变量

To indicate explicitly that a variable is a session variable, precede its name by SESSION, @@session., or @@. 为了明确表示变量是会话变量,请在其名称前加上SESSION,@@ session。或@@。

User-Defined Variables : 用户定义的变量

User variables are written as @var_name, where the variable name var_name consists of alphanumeric characters, “.”, “_”, and “$”. 用户变量写为@var_name,其中变量名var_name由字母数字字符“。”,“ _”和“ $”组成。 A user variable name can contain other characters if you quote it as a string or identifier (for example, @'my-var', @"my-var", or @ my-var ). 如果您将用户变量名称引为字符串或标识符,则它可以包含其他字符(例如,@'my-var',@“ my-var”或@ my-var )。

From the same documentation & using system variable docs - 来自相同的文档使用系统变量docs-

To indicate explicitly that a variable is a global variable, precede its name by GLOBAL or @@global.. The SUPER privilege is required to set global variables. 为了明确表明变量是全局变量,请在其名称前加上GLOBAL或@@ global。设置全局变量必须具有SUPER特权。

To indicate explicitly that a variable is a session variable, precede its name by SESSION, @@session., or @@. 为了明确表示变量是会话变量,请在其名称前加上SESSION,@@ session。或@@。 Setting a session variable requires no special privilege, but a client can change only its own session variables, not those of any other client. 设置会话变量不需要特殊特权,但是客户端只能更改其自己的会话变量,而不能更改任何其他客户端的会话变量。

LOCAL and @@local. 本地和@@ local。 are synonyms for SESSION and @@session.. 是SESSION和@@ session的同义词。

The @@var_name syntax for system variables is supported for compatibility with some other database systems. 支持系统变量的@@ var_name语法,以便与某些其他数据库系统兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM