Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Mysql database Too many connections error troubleshooting

Shulou Source: shulou.com Published: 2022-06-03 05:30:42 09月15日 Update

Phenomenon

Errors such as ERROR: Too many connections are frequently reported in log logs.

Analysis.

When we see such an error, we probably know why the number of connections is full, or there is a problem in the code that leads to unreasonable connection closure. I always insist on the transmission of ideas first, supplemented by knowledge. Why, because we are all smart people, thinking about how to do that everyone has their own way, so that everyone can make the fastest progress.

All right, there's a lot of nonsense. Let's get back to the point. Why did I mention the idea above? Because only when you have this way of thinking can you do it! Most of the time we want to do something, but we have no ideas! So learning is thinking, not knowledge at all!

After we know the possible causes, we have to investigate them one by one. The general steps are as follows:

1. Look at the number of connections. The maximum number of connections configured by MySQL is 100. however, the maximum number of connections on the application side is 3040 at most. This problem should not occur, so pass is dropped.

2. The rest is the code, focusing on the sql section, which is placed in the place where the connection is established and released for troubleshooting

Source code:

Pool.getConnection (function (err, connection) {

If (err) throw err

Connection.query (sql, function (err, rows, fields) {

If (err) {

Return cosole.error (err)

}

Cb (rows)

});

/ / release this connection

Connection.release ()

Do you see a problem? Well, I guess, I can't tell ~

In fact, the children's shoes with a little bit of knowledge of the code should be able to see that the release connection statement is in the wrong position.

After modification:

Pool.getConnection (function (err, connection) {

If (err) throw err

Connection.query (sql, function (err, rows, fields) {

/ / release the connection

Connection.release ()

If (err) {

Return cosole.error (err)

}

Cb (rows)

3. Verify after revision, everything is all right, Amitabha Buddha!

Tags: Ideas code that is problems agents ideas knowledge unreasonable wrong maximum fastest smartest frequent everything is fine everything location reason only place nonsense Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Tech Info MySQL NVidia vpn