MySQL Variable Classification and Usage Analysis

Source: Internet
Author: User


MySQL has two types of variables: local variables and Session-level variables: most configuration options of www.2cto.com MySQL have corresponding Session-level or Global-level variables which can be changed in client programs such as mysql, thus affecting MySQL's response to mysql connection and setting Global-level variables, the impact is that session-level variables are set for all mysql connections connected to the server. The impact is that the server's response to the current connection sets the system level. The two variables are set @ global. var_name =; set @ session. var_name =; User: You can set custom variables to store the data to be reused, so that local variables can be used in subsequent programs: declare with declare, it can only be used in the in end statement block and must be defined at the beginning of the begin end statement block. It is usually used in storage programs such as 01 create procedure sp1 (x VARCHAR (5 )) 02 BEGIN03 DECLARE xname VARCHAR (5) DEFAULT 'bob'; 04 DECLARE newname VARCHAR (5); 05 DECLARE xid INT; 06 www.2cto.com 07 SELECT xname, id INTO newname, xid08 FROM table1 WHERE xname = xname; 09 SELECT newname; 10 END; session-level variable: Also called session variable, set with set, all variables that can be used in the following sections can be used: 1 SET @ t1 = 0, @ t2 = 0, @ t3 = 0; 2 SELECT @ t1: = (@ t2: = 1) + @ t3: = 4, @ t1, @ t2, @ t3; Author: Liu Yun Zhuge

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.