- MySQL知识库 :: configuration
- Maximum Connection Limit Nearing Or Reached
-
Description
The max_connections variable is used to set a limit of how many concurrent user connections are allowed. Maximum concurrent user connections is also known as number of sessions that each server will support. This can be important as there are several internal buffers that are allocated on a per-session basis. By allowing too many connections, you risk exhausting all of the host machine's available RAM. This can lead to crashes and other undesirable outcomes. If you have set max_connections too low, your client users or client applications will not be allowed to connect until the connection count is less than max_connections. Therefore, you will have to choose between how many concurrent connections you need and how much of a system's resources you are willing to allocate to MySQL.
Best Practice
The MySQL Enterprise Monitor will alert you to this problem whenever the ratio of the status variable threads_connected to the global variable max_connections exceeds your notification threshold. By default, this is 95%. To change the value of max_connections, execute the following SQL statement on the server:
SET GLOBAL max_connections = value
Setting the value above too low may cause the server to refuse some client connection attempts. Setting it too high can exhaust server resources. Always try to use a value just large enough to handle your peak connection load. The status variable max_used_connections will tell you the maximum number of concurrent connections you have had since the server restarted or FLUSH STATUS statement was executed.