Tag: Ike its select ROM Operation connection description comparison system
variables
category System variables: global variable session variable custom variable: user variable local variable description system variable: Description: Variable defined by system, not user defined, at server level NOTE: Global variables need to be added to the GLOBALS keyword, session variables need to be added to the sessions keyword, and if not written, the default session-level custom variable: Description: Variables are user-defined rather than system-provided use steps: 1 , Statement 2 , Assignment 3. Use (view, compare, calculate, etc.)
System Variables
global variable scope: Valid for all sessions (connections), but not across reboots1, view all global variables show global VARIABLES;2, view some system variables that meet the conditions show GLOBAL VARIABLES like'%char%';3, view the value of the specified system variable select @ @global. autocommit;4, assign a value set @ @global to a system variable. Autocommit=0; SET GLOBAL autocommit=0; Session Variable scope: valid for current session (connection)1, view all session variables show [session] VARIABLES;2, view some session variables that meet the criteria show [session] VARIABLES like'%char%';3, view the value of the specified session variable select @@[session. autocommit;4, assigning a value set @@[session to a session variable. Autocommit=0; SET [SESSION] autocommit=0;
Custom Variables
User Variable scope: valid for current session (connection), scoped to session variable1, declare and initialize the SET @ variable name=value; SET @ variable Name:=value; SELECT @ variable Name:=value;2, Assignment (update value of variable) way one: SET @ variable name=value; SET @ variable Name:=value; SELECT @ variable Name:=value; mode two: SELECT field into @ variable name from table;3, use (see Value of variable) SELECT @ variable name; local variable scope: Valid only in the begin end block that defines it, applied to the first sentence in Begin end1, declaring DECLARE variable name type; DECLARE variable name type [default value];2, assignment (updating the value of a variable) way one: SET variable name=value; SET Variable Name:=value; SELECT Variable Name:=value; mode two: SELECT field into variable name from table;3, use (view variable's value) SELECT variable name; Case 1, declare two variables, sum and print # user variable SET @m=1; SET @n=1; SET @sum[Email protected]+@n; SELECT @sum; # local variable DECLARE m INT DEFAULT1; DECLARE N INT DEFAULT1; DECLARE sum INT; SET sum=m+N; SELECT sum; difference Scope definition location syntax user variable any place in the current session session plus the @ symbol, without referring to Defined type local variable definition It's Begin end the first sentence of Begin end does not add @, you need to specify the type
Mysql_ Basic _ variable