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

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

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

1. Check the maximum number of connections

show variables like '%max_connections%';

2. Modify the maximum number of connections

set GLOBAL max_connections = 200;

The following article mainly introduces the modification of the maximum number of MySQL connections. We all know that the default value of the maximum number of MySQL connections is 100. This value is far from enough for applications with many concurrent database connections. When the connection request is greater than the default number of connections, an error will occur that the database cannot be connected, so we need to increase it appropriately. Can not connect to MySQL server. Too many connections”-mysql 1040 has reached the upper limit of MySQL. Usually, the maximum number of MySQL connections is 100 by default, and can reach 16384 at most.

Too many MySQL database connections cause system errors and the system cannot connect to the database. The key lies in two data:

1. The maximum number of connections allowed by the database system max_connections . This parameter is configurable. If not set, the default is 100.

2. The current number of database connection threads: threads_connected . This changes dynamically.

We will talk about how to check max_connections and max_connections below.

If threads_connected == max_connections , the database system cannot provide more connections. At this time, if the program wants to create a new connection thread, the database system will refuse unless the program does too much error handling.

Because creating and destroying database connections will consume system resources. In order to avoid opening too many connection threads at the same time, current programming generally uses the so-called database connection pool technology.

However, database connection pool technology cannot prevent program errors from causing exhaustion of connection resources.

This situation usually occurs when the program fails to release the database connection resources in time or other reasons cause the database connection resources to not be released. A simple way to check for similar errors is to constantly monitor the changes in threads_connected when refreshing the page. If max_connections is large enough and the threads_connected value continues to increase until it reaches max_connections, then you should check your program. Of course, if the database connection pool technology is used, threads_connected will no longer grow when it reaches the maximum number of connection threads in the database connection pool.

Check max_connections

show variables like "max_connections";

The results are as follows:

+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 100 |
+-----------------+-------+

View threads_connected

show status like 'Thread_%';

The results are as follows:

+-------------------+------+
| Variable_name | Value |
+-------------------+------+
| Threads_cached | 0 |
| Threads_connected | 1 |
| Threads_created | 1 |
| Threads_running | 1 |
+-------------------+------+

Setting max_connections

To set it, find the max_connections item in the my.cnf file and modify it. If there is no such item, add a line under [mysqld]:

[mysqld] 
max_connections=1000

After the modification is complete, restart MySQL. Of course, you should look at max_connections to make sure it is set correctly.

Notice:

  • 1. It says 1000 here. Please modify according to actual requirements;
  • 2. The maximum number of allowed connections has been added, which does not significantly increase system consumption.
  • 3. If your MySQL uses my.ini as the configuration file, the settings are similar, but the format of the settings needs to be slightly modified.

Other things to note:

When programming, when you use MySQL statements to call the database, a temporary variable will be created before each statement is executed to open the database. Therefore, when you use MySQL statements, remember to close the MySQL temporary variable after each call to MySQL.

In addition, for documents with large traffic, you can consider writing them directly into text. Based on the predicted traffic, first define the file names if there are 100 files. When necessary, analyze the data in all text files and then import them into the database.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Summary of tips for setting the maximum number of connections in MySQL
  • Summarize two ways to modify the maximum number of connections in MySQL
  • Share 3 methods to modify the maximum number of MYSQL connections
  • How to increase the maximum number of connections in mysql
  • 3 ways to correctly modify the maximum number of connections in MySQL
  • How to set the maximum number of connections in MySQL

<<:  CentOS7 upgrade kernel kernel5.0 version

>>:  Problems and solutions of using jsx syntax in React-vscode

Recommend

How to implement batch deletion of large amounts of data in MySQL large tables

The question is referenced from: https://www.zhih...

Win10 install Linux ubuntu-18.04 dual system (installation guide)

I installed a Linux Ubuntu system on my computer....

React.js framework Redux basic case detailed explanation

react.js framework Redux https://github.com/react...

Summary of Vue first screen performance optimization component knowledge points

Vue first screen performance optimization compone...

CSS3 realizes text relief effect, engraving effect, flame text

To achieve this effect, you must first know a pro...

How to avoid duplication of data when inserting in MySql batch

Table of contents Preface 1. insert ignore into 2...

HTML realizes real-time monitoring function of Hikvision camera

Recently the company has arranged to do some CCFA...

Several commonly used methods for centering CSS boxes (summary)

The first one: Using the CSS position property &l...

How to use DPlayer.js video playback plug-in

DPlayer.js video player plug-in is easy to use Ma...

Implementation of Docker building Maven+Tomcat basic image

Preface In Java programming, most applications ar...

Solve the problem of Nginx returning 404 after configuring proxy_pass

Table of contents 1. Troubleshooting and locating...

Writing a web calculator using javascript

This article mainly records the effect of using j...

Detailed explanation of CSS text decoration text-decoration &amp; text-emphasis

In CSS, text is one of the most common things we ...