You can set environment variables in the MySQL database through the following three methods: Using the command line: export MYSQL_ENV_VAR=VALUE Using the .env file: MYSQL_ENV_VAR=VALUE Using the MySQL configuration file: Add env- under the [mysql] section var=VALUE
How to set environment variables in MySQL database
Method 1: Using the command line
In the command line, run the following command:
<code>export MYSQL_ENV_VAR=VALUE</code>
Where, MYSQL_ENV_VAR
is the name of the environment variable, VALUE
is the value to be set value.
For example, to set the MYSQL_USER
environment variable to root
:
<code>export MYSQL_USER=root</code>
Method 2: Use .env
File
Create a file named .env
and add the following lines:
<code>MYSQL_ENV_VAR=VALUE</code>
Place the .env
file where required directory using environment variables.
Method 3: Using the MySQL configuration file
In the MySQL configuration file (usually located at /etc/my.cnf
), add the following lines :
<code>[mysql] env-var=VALUE</code>
Among them, [mysql]
is the name of the client part, env-var
is the name of the environment variable, VALUE
is the The value to set.
For example, to set the MYSQL_USER
environment variable to root
:
<code>[mysql] user=root</code>
Note:
printenv
command to check the value of the environment variable. The above is the detailed content of How to configure mysql database environment variables. For more information, please follow other related articles on the PHP Chinese website!