I am storing images in MYSQL.
Tengo mesa como
CREATE TABLE myTable (id INT, myImage BLOB);
When I am trying to insert
4.7MB file, I am getting exception as
com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4996552 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.
I believe this is related to image size only. Is there any other variable type that I can use?
As per older SO question, I also tried with
MEDIUMBLOB pero sigo recibiendo el mismo error.
At the start of the project, I execute below query and everything is working now
SET GLOBAL max_allowed_packet = 1024*1024*14;
preguntado el 03 de julio de 12 a las 23:07
As the error says, it has nothing to do with variable type but rather the
You must increase this value if you are using large
BLOBcolumns or long strings. It should be as big as the largest
BLOByou want to use. The protocol limit for
max_allowed_packetis 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.
Para usuarios de Windows:
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 podría 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 Grupo cual es
[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 seguido por
net start MySQL).
Seguir funcionó para mí
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
The max_allowed_packet variable has a default value set in the configuration file (my.ini in my case). If your application tries to execute a query whose packet size exceeds this value, this exception is thrown.
My setup is on a Windows 10 machine with MySQL Server 8.0.
I copied the my.ini file with my desired value (64M) for max_allowed_packet to the various possible locations (C:\my.ini, C:\Windows\my.ini). Then restarted the mysql server. It didn't work. When I queried the database for the max_allowed_packet variable, the value remained unchanged.
Los siguientes pasos funcionaron:
I discovered that there is a my.ini file at a different location.
Open the my.ini file at the following location C:\ProgramData\MySQL\MySQL Server 8.0. This has lots of entries, besides max_allowed_packet.
Locate the entry for max_allowed_packet, and set it to the desired value (for e.g. 64M).
Save and close the my.ini file.
Restart the MySQL80 service.
Log into to the mysql server prompt and run the query
show variables like 'max_allowed_packet';
You should see the value set to your desired value.