Detailed explanation of two methods for setting global variables and session variables in MySQL

Detailed explanation of two methods for setting global variables and session variables in MySQL

1. There are two ways to modify global variables in MySQL:

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 figure below. Restarting the database service will make the global variables take effect.

We open several MySQL command lines and can see that the variables in all sessions are effective, as shown in the figure

Method 2: Use the keyword global to set global variables without modifying the configuration file

set global autocommit=1;

Set the value of the autocommit variable to ON

It should be noted that the setting of global variables using this method is only valid for newly opened sessions and is not effective for already opened sessions.

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

set session autocommit=1;

Modifying the session variable configuration is only effective for the variable configuration of this session and is invalid for other sessions.

3. Although global variables and session variables are set, the database configuration will be reinitialized after the MySQL service is restarted, and everything will be initialized according to the configuration of my.ini. Both global and session configurations will become invalid.

Summarize

The above is the method of setting global variables and session variables in MySQL that I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and I will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

You may also be interested in:
  • Example of writing lazy UNION in MySQL using custom variables
  • Detailed explanation of mysql user variables and set statement examples
  • MySQL variable principles and application examples
  • Detailed explanation of MySQL startup options and system variables examples
  • Example analysis of mysql variable usage [system variables, user variables]
  • How to create (CREATE PROCEDURE) and call (CALL) a MySQL stored procedure and how to create (DECLARE) and assign (SET) a variable
  • 15 important variables you must know about MySQL performance tuning (summary)
  • MySQL 8.0.12 installation and environment variable configuration tutorial under win10
  • MySQL 5.6.23 Installation and Configuration Environment Variables Tutorial
  • The concept and characteristics of MySQL custom variables

<<:  Nginx load balancing algorithm and failover analysis

>>:  Basic usage examples of Vue named slots

Recommend

HTML table layout example explanation

The elements in an HTML document are arranged one...

MYSQL local installation and problem solving

Preface This article is quite detailed and even a...

Several ways to connect tables in MySQL

The connection method in MySQL table is actually ...

Summary of the use of special operators in MySql

Preface There are 4 types of operators in MySQL, ...

Causes and solutions for MySQL too many connections error

Table of contents Brief summary At noon today, th...

Getting Started: A brief introduction to HTML's basic tags and attributes

HTML is made up of tags and attributes, which are...

Test and solution for MySQL's large memory usage and high CPU usage

After the changes: innodb_buffer_pool_size=576M -...

What to do if you forget the initial password of MySQL on MAC

The solution to forgetting the initial password o...

Solve the problem that the IP address obtained using nginx is 127.0.0.1

Get ip tool import lombok.extern.slf4j.Slf4j; imp...

Learn the key knowledge that must be mastered in the Vue framework

1. What is Vue Vue is a progressive framework for...

Mini Program to Implement Paging Effect

This article example shares the specific code for...

Start nginxssl configuration based on docker

Prerequisites A cloud server (centOS of Alibaba C...

Ubuntu20.04 VNC installation and configuration implementation

VNC is a remote desktop protocol. Follow the inst...

MySQL 5.6.27 Installation Tutorial under Linux

This article shares the installation tutorial of ...