How To Update Maximum Number Of Mysql Connections On Linux

By | February 20, 2009

There is often necessary to increase the maximum number of MySQL connections in order to prevent “Too Many Connections” error. If you’re on LAMP, you’re welcome to follow one of these ways:

For a temporary solution you might want to execute the following query:

SET GLOBAL max_connections = 500;

This will increase max_connections directive to 500, but will work until MySQL is restarted. If you’re seekining for a permanent solution, the following strings should help you.

First of all, you need to locate my.cnf file. It is usually located at /etc/my.cnf. You’re welcome to create it if it does not exist as there usually are some sample files in the /etc.  Then you need to put the following string:

[mysqld]
max_connections = 500

If you already have a [mysqld] section, then you just need to add the string related to max_connections. Else, if you’re using a blank file, you should copy and paste the code above.

When the file is saved, you’re welcome to restart MySQL in the way you like as these changes will be applied after restart. Acommon command to do this is service mysqld restart.

Hope this helps you to maintain your server with a good number of MySQL connections