Get the App
SLTechnology News&Howtos  ›  Database  › 

Detailed explanation of two methods of setting global variable and session variable by MySQL

Shulou Source: shulou.com Published: 2022-06-01 04:25:27 11月04日 Update

1. To modify global variables in MySQL, there are two ways:

Method 1: Modify the my.ini configuration file. If you want to set global variables, the easiest way is to write the variable configuration directly in the my.ini file, as shown in the following figure. Restart the database service to make global variables effective.

We open a few mysql command lines, you can see that all the variables in the session are in effect, as shown in the figure

Method 2: On the basis of not modifying the configuration file, use the keyword global to set global variables.

set global autocommit=1;

Set the value of the autocommit variable to ON

Note that setting the global variable using this method is valid only for newly opened sessions, not for sessions that are already open.

2. To modify session variables in MySQL, you can use the session keyword, such as:

set session autocommit=1;

Modify session variable configuration, only valid for this session variable configuration, invalid for other sessions.

Although global variables and session variables are set, after the MySQL service restarts, the database configuration will be reinitialized, and everything will be initialized according to the configuration of my.ini. Both global and session configurations are disabled.

summary

The above is the MySQL global variable and session variable method introduced to you by Xiaobian. I hope it will help you. If you have any questions, please leave a message to me. Xiaobian will reply to you in time. Thank you very much for your support!

Tags: Variable configuration global method file valid key keyword data database is in service can make command foundation way this method question website as shown in the figure Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info Docker Xiaomi Huawei