Get the App
SLTechnology News&Howtos  ›  Database  › 

How to modify the maximum number of mysql connections

Shulou Source: shulou.com Published: 2022-05-31 12:48:10 09月16日 Update

This article focuses on "how to modify the maximum number of mysql connections", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to modify the maximum number of connections in mysql.

Modify the method: 1, execute the "set GLOBAL max_connections= connection value;" command. 2. Open the mysql configuration file "my.cnf", add the "max_connections= connection value" statement to the file, save the file and restart the service.

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

The maximum number of connections can be modified through mysql. There are two common ways to modify the maximum number of connections in mysql database. Today, we analyze the characteristics and differences between the two methods, so that we can better maintain mysql. Let's take a look at how mysql modifies the maximum number of connections. I hope the article can help you.

problem

When using MySQL databases, we often encounter such a problem, which is the "Can not connect to MySQL server. Too many connections"-mysql 1040 error, because the number of connections that have not been released to MySQL has reached the MySQL limit. In general, the maximum number of connections for mysql is 100 by default, and the maximum can reach 16384.

There are two common ways to modify the maximum number of connections.

Solution 1: through the command

You can set the maximum number of connections to 100 through the set GLOBAL max_connections=100; command, which takes effect immediately and does not require a restart of the mysql service.

It should be noted that the operation can only be done through the mysql account with root permission, otherwise an error of "1227-Access denied; you need (at least one of) the SUPER privilege (s) for this operation" will be reported.

At the same time, set the minimum max_connections to 1.

Solution 2: modify my.cnf

Open the mysql configuration file vim / etc/my.cnf, add the max_connections=100 line (if any, directly modify the value), and then restart the service: / etc/init.d/mysqld restart, which takes effect.

Difference:

1. By modifying the configuration file, the service needs to be restarted, and the command modification takes effect immediately.

two。 By modifying the configuration file, it is more stable and reliable. Because if there is max_connections=100 in the configuration file, and then modify it with the command, once the mysql service is restarted, the number of connections specified in the configuration file will prevail again.

At this point, I believe you have a deeper understanding of "how to modify the maximum number of mysql connections". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Maximum file configuration command method service method content can be passed commonly used numerical data database friend error problem learning practical deeper minimum Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Apple Shulou Technology Shulou Information macOS