Cómo cambiar el tamaño máximo permitido del paquete


Estoy teniendo un problema con los campos de BLOB en mi base de datos MySQL - al cargar archivos de más de 1MB aproximadamente me sale un error Packets larger than max_allowed_packet are not allowed.

Esto es lo que he intentado:

En MySQL Query Browser corrí un show variables like 'max_allowed_packet' que me dio 1048576.

Luego ejecuto la consulta set global max_allowed_packet=33554432 seguida de show variables like 'max_allowed_packet' - me da 33554432 como se esperaba.

Pero cuando reinicio el servidor MySQL, mágicamente vuelve a 1048576. ¿Qué estoy haciendo mal aquí?

Pregunta adicional, ¿es posible ¿comprimir un campo de BLOB?

 242
Author: Muleskinner, 2011-11-09

11 answers

Cambio en el archivo my.ini o ~/.my.cnf incluyendo la única línea bajo la sección [mysqld] en su archivo:

max_allowed_packet=500M

Luego reinicie el servicio MySQL y habrá terminado.

Véase la documentación para más información.

 315
Author: Manuel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-02 11:00:46

La variable max_allowed_packet se puede establecer globalmente ejecutando una consulta.

Sin embargo, si no lo cambia en el archivo my.ini (como sugirió dragon112), el valor se restablecerá cuando se reinicie el servidor, incluso si lo establece globalmente.

Para cambiar el paquete máximo permitido para todos a 1 GB hasta que el servidor se reinicie:

SET GLOBAL max_allowed_packet=1073741824;
 168
Author: TehShrike,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-06-13 16:02:13

Uno de mis desarrolladores junior estaba teniendo un problema modificando esto para mí, así que pensé en ampliar esto con mayor detalle para los usuarios de linux:

1) abrir terminal

2) ssh root@YOURIP

3) introduzca la contraseña de root

4) nano /etc/mysql/my.cnf (si el comando no es reconocido haga esto primero o intente vi y luego repita: yum install nano )

5) agregue la línea: max_allowed_packet=256M (obviamente ajuste el tamaño para lo que necesite) en la sección [MYSQLD]. Hizo un error de ponerlo en la parte inferior del archivo primero por lo que no funcionó.

introduzca la descripción de la imagen aquí

6) Control + O (guardar) luego ENTER (confirmar) luego Control + X (salir del archivo)

7) servicio mysqld reiniciar

8) Puede comprobar el cambio en la sección variables en phpmyadmin

 69
Author: naw103,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-10-27 11:46:31

Creo que algunos también querrían saber cómo encontrar el mi.archivo ini en su PC. Para los usuarios de Windows, creo que la mejor manera es la siguiente:

  1. Win+R(acceso directo para "ejecutar"), escriba servicios.msc, Enter
  2. Puede encontrar una entrada como 'MySQL56', haga clic derecho sobre ella, seleccione propiedades
  3. Usted podría ver sth como "D:/Program Files / MySQL / MySQL Server 5.6 / bin \ mysqld" def defaults-file = "D:\ProgramData\MySQL\MySQL Servidor 5.6 \ my.ini" MySQL56

Recibí esta respuesta de http://bugs.mysql.com/bug.php?id=68516

 31
Author: fstang,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-11-22 03:30:11

Siguiendo todas las instrucciones, esto es lo que hice y trabajé:

mysql> SELECT CONNECTION_ID();//This is my ID for this session.
+-----------------+
| CONNECTION_ID() |
+-----------------+
|              20 |
+-----------------+
1 row in set (0.00 sec)

mysql> select @max_allowed_packet //Mysql do not found @max_allowed_packet
+---------------------+
| @max_allowed_packet |
+---------------------+
| NULL                |
+---------------------+
1 row in set (0.00 sec)

mysql> Select @@global.max_allowed_packet; //That is better... I have max_allowed_packet=32M inside my.ini
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                    33554432 |
+-----------------------------+
1 row in set (0.00 sec)

mysql> **SET GLOBAL max_allowed_packet=1073741824**; //Now I'm changing the value.
Query OK, 0 rows affected (0.00 sec)

mysql> select @max_allowed_packet; //Mysql not found @max_allowed_packet
+---------------------+
| @max_allowed_packet |
+---------------------+
| NULL                |
+---------------------+
1 row in set (0.00 sec)

mysql> Select @@global.max_allowed_packet;//The new value. And I still have max_allowed_packet=32M inisde my.ini
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                  1073741824 |
+-----------------------------+
1 row in set (0.00 sec)

Así que, como podemos ver, el max_allowed_packet se ha cambiado fuera de mi.ini.

Vamos a salir de la sesión y comprobar de nuevo:

mysql> exit
Bye

C:\Windows\System32>mysql -uroot -pPassword
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.6.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT CONNECTION_ID();//This is my ID for this session.
+-----------------+
| CONNECTION_ID() |
+-----------------+
|              21 |
+-----------------+
1 row in set (0.00 sec)

mysql> Select @@global.max_allowed_packet;//The new value still here and And I still have max_allowed_packet=32M inisde my.ini
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                  1073741824 |
+-----------------------------+
1 row in set (0.00 sec)

Now I will stop the server
2016-02-03 10:28:30 - Server is stopped

mysql> SELECT CONNECTION_ID();
ERROR 2013 (HY000): Lost connection to MySQL server during query


Now I will start the server
2016-02-03 10:31:54 - Server is running


C:\Windows\System32>mysql -uroot -pPassword
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.26-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SELECT CONNECTION_ID();
+-----------------+
| CONNECTION_ID() |
+-----------------+
|               9 |
+-----------------+
1 row in set (0.00 sec)

mysql> Select @@global.max_allowed_packet;//The previous new value has gone. Now I see what I have inside my.ini again.
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                    33554432 |
+-----------------------------+
1 row in set (0.00 sec)

Conclusión, después de ESTABLECER GLOBAL max_allowed_packet=1073741824, el servidor tendrá el nuevo max_allowed_packet hasta que se reinicie, como alguien dijo anteriormente.

 17
Author: zwitterion,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-03 18:15:51

Si se obtiene este error mientras se realiza una copia de seguridad, max_allowed_packet se puede establecer en el my.cnf particularmente para mysqldump.

[mysqldump]
max_allowed_packet=512M

Seguí recibiendo este error mientras realizaba un mysqldump y no entendí porque tenía este conjunto en my.cnf bajo la sección [mysqld]. Una vez que descubrí que podía configurarlo para [mysqldump] y establecí el valor, mis copias de seguridad se completaron sin problemas.

 12
Author: xpros,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-02-02 11:01:18

Para aquellos que ejecutan wamp mysql server

Icono de la bandeja Wamp - > MySQL - > my.ini

[wampmysqld]
port        = 3306
socket      = /tmp/mysql.sock
key_buffer_size = 16M
max_allowed_packet = 16M        // --> changing this wont solve
sort_buffer_size = 512K

Desplácese hacia abajo hasta el final hasta que encuentre

[mysqld]
port=3306
explicit_defaults_for_timestamp = TRUE

Agregue la línea de packet_size entre

[mysqld]
port=3306
max_allowed_packet = 16M
explicit_defaults_for_timestamp = TRUE

Compruebe si funcionó con esta consulta

Select @@global.max_allowed_packet;
 8
Author: Sayka,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-29 09:38:23

Muchos de los que respondieron detectaron el problema y ya dieron la solución.

Solo quiero sugerir otra solución, que es cambiar el valor de la variable Glogal desde la herramienta Mysql Workbench. Eso es por supuesto SI usa Workbench ejecutándose localmente en el servidor (o a través de una conexión SSH)

Simplemente conéctese a su instancia y vaya al menú:

Servidor - > Archivo de opciones -> Redes - > max_allowed_packed

Se establece el valor deseado y entonces necesita reiniciar el servicio MySQL.

 4
Author: cnom,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-09 14:16:30

Este error se debe a que sus datos contienen un valor mayor que el establecido.

Simplemente escriba el max_allowed_packed=500M o puede calcular que 500 * 1024k y utilizar que en lugar de 500M si lo desea.

Ahora solo reinicia MySQL.

 3
Author: Suresh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-11-10 04:03:56

Para cualquiera que ejecute MySQL en el servicio Amazon RDS, este cambio se realiza a través de grupos de parámetros. Necesita crear un nuevo PG o usar uno existente (que no sea el predeterminado, que es de solo lectura).

Debe buscar el parámetro max_allowed_packet, cambiar su valor y luego presionar guardar.

De vuelta en su instancia MySQL, si ha creado un nuevo PG, debe adjuntar el PG a su instancia (es posible que necesite un reinicio). Si ha cambiado un PG que ya estaba conectado a su instancia, los cambios se aplicarán sin reiniciar, a todas las instancias que tengan ese PG adjunto.

 2
Author: SebaGra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-03-01 13:18:00

Si desea cargar una imagen de gran tamaño o datos en la base de datos. Simplemente cambie el tipo de datos a 'BIG BLOB'.

 0
Author: Vishal J,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-08-28 06:48:15