mysql--variable

Source: Internet
Author: User

First, System variables
Description: Variables are defined by the system, not user defined, and belong to the server level
Note: Global variables need to be added to the GLOBALS keyword, session variables need to be added to the sessions keyword, if not written, the default session level
Steps to use:
1. View all system Variables
Show global| "Session" variables;
2. View some system variables that meet the criteria
Show global| "session" variables like '%char% ';
3. View the value of the specified system variable
SELECT @ @global | "Session" system variable name;
4. Assigning a value to a system variable
Way One:
Set global| "session" System variable name = value;
Way two:
SET @ @global | "Session" SYSTEM variable name = value;
1.1 Global variables
Scope: Valid for all sessions (connections), but not across reboots
Precise use of select imprecise usage show
① View All global variables
SHOW GLOBAL VARIABLES;
② viewing partial system variables that meet the criteria
SHOW GLOBAL VARIABLES like '%char% ';
③ View the value of a specified system variable
SELECT @ @global. autocommit;
④ Assigning a value to a system variable
SET @ @global. autocommit=0;
SET GLOBAL autocommit=0;
1.2 Session Variables
Scope: Valid for current session (connection)
① View all Session variables
SHOW SESSION VARIABLES;
② viewing partial session variables that meet the criteria
SHOW SESSION VARIABLES like '%char% ';
③ View the value of the specified session variable
SELECT @ @autocommit;
SELECT @ @session. tx_isolation;
④ Assigning a value to a session variable
SET @ @session. tx_isolation= ' read-uncommitted ';
SET SESSION tx_isolation= ' read-committed ';
Ii.. Custom variables
Description: The variable is customized by the user, not the system-supplied
Steps to use:
1. Statement
2. Assign Value
3. Use (view, compare, calculate, etc.)
2.1 User Variables
Scope: Valid for current session (connection), scoped to session variable
Assignment operator: = or: =
① declaring and initializing
SET @ variable name = value;
SET @ variable Name: = value;
SELECT @ variable Name: = value;
② Assignment (update the value of the variable)
Way One:
SET @ variable name = value;
SET @ variable Name: = value;
SELECT @ variable Name: = value;
Way two:
SELECT field into @ variable name
from table;
③ (View the value of a variable)
SELECT @ variable name;
2.2 Local Variables
Scope: Valid only in the begin end block that defines it
Apply the first sentence in the Begin end
② Assignment (update the value of the variable)
Way One:
SET local variable name = value;
SET local variable name: = value;
SELECT local variable name: = value;
Way two:
SELECT field into with variable name
from table;
③ (View the value of a variable)
SELECT local variable name;

Comparison of user variables and local variables

mysql--variable

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.