Four types of variables for MySQL

Source: Internet
Author: User

I. Global variables
Changes its parameters dynamically during system operation and fails after a reboot.
SET gloabl var=xxx;
SET @ @global. var=xxx; (set @ @var =xxx)
These two methods are equivalent

View the global variables of the system
Show global variables [like "%"];

Two. User variables
Valid for the current reply, the variable is destroyed after the reply is completed
SET @var =xxx;
SELECT @var: =uid from table where id=10;
With @ as the prefix identifier, set can use = or =: assignment, select can only be assigned by: =


Three. Session variables
Valid for the current reply, the variable is destroyed after the reply is completed
Set session Var_name = value;
SET @ @session. Var_name = value;
Set var_name = value;
The above three methods are equivalent

The difference between a session variable and a user variable is that, in addition to the prefix identifier, the session variable is a predefined set of variables, and you cannot define a user variable that does not exist.
Such as
Set test= ' test ';
[ERR] 1193-unknown system variable ' test ';

View variables for the current session
Show [session] variables [like "%"];(where session is the default and can not be written)

Common like eliminate MySQL default sql_mode mode, change to the most relaxed mode
Set sql_mode= ";


Four. Local variables
declear var INTEGER DEFAULT 0;
Generally defined between the begin and end statement blocks, the end of the statement block disappears.

Ps:
Between Begin and end is used to define a set of SQL compound statements;

Four types of variables for MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.