Tuesday, January 19, 2010

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
max_allowed_packet=50M

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

And viola, then restart the server.

/etc/init.d/mysqld restart && tail -f /var/log/mysqld.log

Yeah ! problem solved...