Home >Database >Mysql Tutorial >How to set environment variables in mysql
There are two ways to set environment variables in MySQL: use the SET command: set the environment variable name to the value, and the effective scope is the entire session and all subsequent sessions. Use the SESSION command: Set the environment variable name to a value, which only takes effect in the current session, and clears the variable after the session ends.
How to set environment variables in MySQL
There are two ways to set environment variables in MySQL:
Method 1: Use the SET command
<code>SET 环境变量名 = 值;</code>
For example:
<code>SET @user = 'john';</code>
This command sets the environment variable @user
to the value" john".
Method 2: Use the SESSION command
<code>SET SESSION 环境变量名 = 值;</code>
is similar to the SET
command, but the environment variables set by the SESSION
command are only Valid in the current session. After the session ends, the variables will be cleared.
For example:
<code>SET SESSION @temp_dir = '/tmp';</code>
Using environment variables
After setting environment variables, you can use them to reference variable values.
<code>SELECT * FROM users WHERE username = @user;</code>
Note:
The above is the detailed content of How to set environment variables in mysql. For more information, please follow other related articles on the PHP Chinese website!