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

Use a few interview questions to look at the JavaScript execution mechanism

Table of contents Previous words Synchronous and ...

Detailed analysis of GUID display issues in Mongodb

Find the problem I recently migrated the storage ...

JS, CSS and HTML to implement the registration page

A registration page template implemented with HTM...

Vue component library ElementUI implements table loading tree data tutorial

ElementUI implements a table tree list loading tu...

How to configure nginx to return text or json

Sometimes when requesting certain interfaces, you...

JavaScript implementation of a simple addition calculator

This article example shares the specific code of ...

Linux uses NetworkManager to randomly generate your MAC address

Nowadays, whether you are on the sofa at home or ...

Detailed installation process of mysql5.7.21 under win10

This article shares the installation of MySQL 5.7...

Example analysis of the page splitting principle of MySQL clustered index

This article uses an example to illustrate the pa...

A detailed introduction to Linux system configuration (service control)

Table of contents Preface 1. System Service Contr...

What are the differences between xHTML and HTML tags?

All tags must be lowercase In XHTML, all tags must...

How to set up scheduled tasks in Linux and Windows

Table of contents Linux 1. Basic use of crontab 2...

Example test MySQL enum type

When developing a project, you will often encount...

Implementation of vertical centering with unknown height in CSS

This article mainly introduces the implementation...