Home > Database > Mysql Tutorial > How to set environment variables in mysql

How to set environment variables in mysql

下次还敢
Release: 2024-04-14 18:45:32
Original
597 people have browsed it

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

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>
Copy after login

For example:

<code>SET @user = 'john';</code>
Copy after login

This command sets the environment variable @user to the value" john".

Method 2: Use the SESSION command

<code>SET SESSION 环境变量名 = 值;</code>
Copy after login

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>
Copy after login

Using environment variables

After setting environment variables, you can use them to reference variable values.

<code>SELECT * FROM users WHERE username = @user;</code>
Copy after login

Note:

  • Environment variable names must start with the '@' symbol.
  • The type of environment variable value can be string, number or Boolean value.
  • Environment variables can be used like other columns in SQL statements.

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!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template