Methods to configure environment variables in MySQL are: Modify the my.cnf file: Add the variable_name=value line in the [mysqld] section. Add command line flag: Use the --variable_name=value flag when starting MySQL. Use the set command: Execute the set variable_name=value command in the MySQL console. Using an ENV file: Load variables from an environment file using the export variable_name=value syntax.
How to configure environment variables in MySQL
Step 1: Edit my.cnf
Edit the MySQL configuration file my.cnf. The file is usually located at /etc/mysql/my.cnf or /etc/my.cnf.
Step 2: Add variable line
In the [mysqld] section, add the following line:
<code>[mysqld] ... variable_name=value ...</code>
Replace variable_name with the name of the environment variable , replace value with the value of the variable.
Step 3: Save and Restart MySQL
Save my.cnf and restart the MySQL service to apply the changes:
<code>sudo service mysql restart</code>
Example
For example, to set test_variable
to my_value
, add the following line to my.cnf:
<code>[mysqld] ... test_variable=my_value ...</code>
Other methods
In addition to using my.cnf, you can also configure environment variables using the following methods:
To verify that the environment variables are configured correctly, execute the following command in the MySQL console:
<code>show variables like 'variable_name';</code>
The above is the detailed content of How to configure environment variables in mysql. For more information, please follow other related articles on the PHP Chinese website!