HoganHost blog

[email protected]

How to restrict the number of MySQL connections by users in Cpanel using SSh

Some server administrators want to restrict the number of user connections to MySQL. There needs to be a consideration of how busy a site may be and how many MySQL connections are needed. A busier site may need 25 connections and ones less active may only need 5. Just use this setting to be able to at least split that max_connections setting so a single user can’t use up all the connections allowed.

Procedure

In order to set user level connection limits, the overall server limit should be set statically as well.

So, the following would be added in /etc/my.cnf under [mysqld].

Editing the Mysql my.cnf File

  1. Login to your server via SSH.
  2. To edit the MySQL settings with nano type the following:
    nano /etc/my.cnf
    3. Add the below on your Mysql my.cnf
max_connections = 150
max_user_connections = 25

Afterward, MySQL/MariaDB needs to be restarted.

/scripts/restartsrv_mysql

This of course may need to be increased if the user’s site starts seeing sporadic “Could not connect to the database.” types of errors. It may also be possible the application is making too many connections as well. That would be something the application developer would need to review though.

Check out our Cheap and Reliable Web hosting service

Leave a Comment

Your email address will not be published. Required fields are marked *