Friday, April 5, 2013

Home Increase max_connections in mysql without restarting mysqld service.



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". I assume that you have enough hardware resources (Mainly RAM )to handle more connections, here with this article I will share a TIP to increase max_connections in mysql.
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)

Note:

It is important that you edit your /etc/my.cnf to add max_connections = 200 otherwise when you restart mysqld service in future, It will complain again after it hits the old max_connections limit.

Thursday, April 4, 2013

Packet for query is too large . You can change this value on the server by setting the max_allowed_packet' variable. OR com.mysql.jdbc.PacketTooBigException



Packet too Big Exception originates from MySQL when the packet of data is too big for MYSQL to handle.
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4739923 > 1048576).
After a whole day of nerves wrecked for this, I figured out that i need to increase the size of "max_allowed_packet variable" in two places at the client's and server's end - as stated by MYSQL (http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html)

mysql> show variables like '%max_allowed_packet';

mysql> set global max_allowed_packet=52428800;

File: /etc/my.cnf (or) my-huge.cnf and my-small.cnf and my-large.cnf files
max_allowed_packet=50M

The maximum allowed packet size is 1GB ie 100MB.
Oh btw, 1 MB = 1048576 bytes.