Thursday 20 September 2012

How to increase max connections in mysql

How to increase max connections in mysql, so that it can handle huge connections from applications.

By default in mysql database server max_connections is set to 100. This value indicates how many maximum concurrent connections mysql server can handle. If mysql reaches to it maximum (max) limit then you can see errors like "too many connections".

As we know my.cnf is default configuration file for mysqld service and by default it is located in /etc directory unless and until you have changed it.
To find out how many max_connections are allowed currently on your mysql server use following command from mysql prompt.
    mysql> select @@max_connections;
    +-------------------+
    | @@max_connections |
    +-------------------+
    | 100 |
    +-------------------+
    1 row in set (0.00 sec)
max_connections is a GLOBAL variable. we can increase it on the fly without restarting mysqld service.
To do so use following command.
    mysql> set global max_connections = 200;
    Query OK, 0 rows affected (0.00 sec)
Now, If you check again you will see that limit of max_connections is increased.
    mysql> select @@max_connections;
    +-------------------+
    | @@max_connections |
    +-------------------+
    | 200 |
    +-------------------+
    1 row in set (0.00 sec)