Get the App
SLTechnology News&Howtos  ›  Database  › 

MySQL view the maximum number of connections and modify the maximum number of connections

Shulou Source: shulou.com Published: 2022-06-01 04:54:35 10月01日 Update

1. View the maximum number of connections

Mysql > show variables like "% max_connections%"; ±- ±- + | Variable_name | Value | ±- ±- + | max_connections | 141 | ±- ±- + 1 row in set (0.00 sec)

2. Modify the maximum number of connections

The default value for the maximum number of connections in MySQL is 100, which is far from enough for database applications with a large number of concurrent connections. When the connection request is greater than the default number of connections, there will be an error that cannot connect to the database, so we need to make it larger appropriately. A problem often encountered when using a MySQL database is a "Can not connect to MySQL server. Too many connections"-mysql 1040 error, which is 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.

Two common ways to modify the maximum number of connections are as follows:

First: the command line modifies the maximum number of connections (max_connections) to set the maximum number of connections to 1000.

Mysql > set global max_connections = 1000

There is a problem with this approach, that is, the maximum number of connections set is only valid for the current MySQL service process, and once MySQL is restarted, it will return to its initial state. Because the initialization work of MySQL after startup reads data from its configuration file, and no changes are made to its configuration file in this way.

Second: modify the maximum number of MySQL connections (max_connections) by modifying the configuration file.

Enter the MySQL installation directory, open the MySQL configuration file my.ini or my.cnf to find max_connections=100, modify it to max_connections=1000, and restart the MySQL service.

Tags: Maximum data file configuration database way that is error problem service valid appropriate upper limit insufficient command regular commonly used numerical time status Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info macOS Linux Microsoft Huawei