com.mysql.jdbc.PacketTooBigException

As the error says, it has nothing to do with variable type but rather the max_allowed_packet variable:

You must increase this value if you are using large BLOB columns or long strings. It should be as big as the largest BLOB you want to use. The protocol limit for max_allowed_packet is 1GB. The value should be a multiple of 1024; nonmultiples are rounded down to the nearest multiple.

But, generally speaking, don't store files in your database - store them in your filesystem and record the path to the file in the database.


Following worked for me

edit my.cnf file ( mine was in /etc/mysql )

Then modify the max_allowed_packet value I set it to max_allowed_packet=200M

Make sure you restart MySQL for change to take effect


For Windows users:

mysql_home points to your mysql/mariadb installation folder.

open cmd, cd to %mysql_home%\bin and run mysqladmin > temp.txt This will spit out a lot of information about the usage of the tool. Somewhere among all that output you will find this information:

Default options are read from the following files in the given order: C:\windows\my.ini C:\windows\my.cnf C:\my.ini C:\my.cnf c:\mariadb-5.5.29-w inx64\my.ini c:\mariadb-5.5.29-winx64\my.cnf

This shows that you could have, if you don't have it already, a file called my.ini or my.conf in the %mysql_home% directory.

create my.ini and add the lines:

[mysqld]
#allow larger BLOBs to be stored
max_allowed_packet = 10M

make sure to include the settings group which is [mysqld] otherwise it will fail to start (and for me it ended up hanging in limbo).

You will now need to restart the MySQL daemon, this is done either by killing and starting the currently running mysqld process or by restarting the MySQL service (run services.msc, locate MySQL, press the restart button; or from cmd, net stop MySQL followed by net start MySQL).

Tags:

Mysql

Blob

Packet