简体   繁体   中英

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?

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 @@?

@@ - 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. (This differs from SET @@var_name = value, which always refers to the session 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

Using System Variables :

To indicate explicitly that a variable is a session variable, precede its name by SESSION, @@session., or @@.

User-Defined Variables :

User variables are written as @var_name, where the variable name var_name consists of alphanumeric characters, “.”, “_”, and “$”. 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 ).

From the same documentation & using system variable 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.

To indicate explicitly that a variable is a session variable, precede its name by SESSION, @@session., or @@. 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. are synonyms for SESSION and @@session..

The @@var_name syntax for system variables is supported for compatibility with some other database systems.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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