8.3 Set Maximum Connection Limits for Server and per User

Information

Limiting concurrent connections to a MySQL server can be used to reduce risk of Denial of Service (DoS) attacks performed by exhausting connection resources.

Rationale:

Limiting the number of concurrent sessions at the server and per user level helps to reduce the risk of DoS attacks. MySQL provides mechanisms to limit the number of simultaneous connections that can be made at the server level or by any given account.

Solution

Connect to the MySQL Database as an administrator.

For example, to set the global default per user to 50 run the command:

SET PERSIST max_user_connections=50;

To control the maximum number of clients the server permits to connect simultaneously, set the max_connections system variable:

SET PERSIST max_connections=1000;

Additionally, this max user connections can be set per user as well as for a given period of time period using CREATE or ALTER.

For example:

ALTER USER 'fred'@'localhost'
WITH MAX_CONNECTIONS_PER_HOUR 5
MAX_USER_CONNECTIONS 2;

Default Value:

The default value of max_connections is 151, max_user_connections is 0 (unlimited, thus limited by max_connections).

See Also

https://workbench.cisecurity.org/files/3844

Item Details

Category: ACCESS CONTROL

References: 800-53|AC-12

Plugin: MySQLDB

Control ID: a4a2c86ebc615fbe88c7c57245b1f048be093c7379993b031b4a242043f85d40