(16) The variables in MySQL

Source: Internet
Author: User

Variable

System variables and custom variables

System variables

System variables: System-defined variables, most of the system variables, generally do not require user control, system variables used to control the performance of the server such as: Autocommit, auto_increment and so on.

viewing system Variables

Show variables;

View variable values for a specific variable: any content that has data returned is a select view

View basic syntax for system variables: select @@ 变量 name;

Eg:select @ @version, @ @autocommit, @ @auto_increment_offset, @ @character_set_results;

modifying system Variables

There are two ways to modify system variables: Session level and global level

Set @@ 变量 name = value;

Set variable name = value;

Session level: Temporary modification, the current client is valid, when the secondary connection is valid.

Global level: One modification, permanent (valid for all clients)

Set global variable name = value;

Other clients need to restart the client to take effect.

Custom variables

In order to differentiate system variables, the system specifies that the custom variable must use an @ symbol.

SET @ variable name = value;

Select variable name;

In MySQL, "=" would implicitly consider the comparison of symbolic processing, and MySQL redefined a new assignment symbol for the concept of distinguishing between comparison and assignment---- : =

MYSQL allows you to get data from a data table and assign it to a variable : two ways

Scenario 1: Edge assignment, side view results

SELECT @ Variable Name: = Field name form data source; --Assigns a field from the database table to the variable.

Scenario 2: Only the assignment does not look at the result, it is strict: only one data record can be obtained, MySQL does not support data.

Select field List from table name into variable list;

The custom variables used are session-level. Variables are not database-sensitive and belong to the user level.

(16) The variables in 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.