Error 'Packet for query is too large' when I tried to make a query on my website

Bob picture Bob · Nov 11, 2017 · Viewed 8.4k times · Source

Again I need your help. I'm trying to put my java web site online.

What I use :

  • MySQL server : command line mysql -V, result : mysql Ver 15.1 Distrib 10.1.23-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
  • Cayenne
  • Debian server
  • Java (Vaadin)

Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the max_allowed_packet' variable.

What I tried :

1. Like the error said, I tried to change the value on the server by doing :

  • Log on my server
  • Connect to MySQL with : mysql -u root
  • Enter : SET GLOBAL max_allowed_packet=1073741824;
  • then, restart the server with : /etc/init.d/mysql restart

But I still have the error.

2. I took a look to : How to change max_allowed_packet size

But, When I did the nano /etc/mysql/my.cnf, the file looks like (I don't have any [mysql]) :

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Nov 10 23:57:02 2017 from 82.236.220.195
root@XXXX:~# nano /etc/mysql/my.cnf
  GNU nano 2.7.4               File: /etc/mysql/my.cnf                Modified

# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
# 2. "/etc/mysql/conf.d/*.cnf" to set global options.
# 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
# 4. "~/.my.cnf" to set user-specific options.
#
# If the same option is defined multiple times, the last one will apply.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

In mysql, the folders/files in the 'mysql' folder is :

enter image description here

Any hint will be very appreciate! Thanks

EDIT: In /etc/mysql/mariadb.conf.d/50-server.cnf, I changed :

  1. max_allowed_packet = 1073741824
  2. max_connections = 100000

and I added : net_buffer_length = 1048576

For info : In my workbench, I can see the server variables : enter image description here

EDIT2 : Now, when I select the variable in command line on the server, I have :

MariaDB [(none)]> SELECT @@global.max_allowed_packet;
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                  1073741824 |
+-----------------------------+
1 row in set (0.00 sec)

SOLUTION Because the error was not explicit.

Thanks to com.mysql.jdbc.PacketTooBigException

My cayenne configuration was :

<url value="jdbc:mysql://IPADDRESS:22/DBBASENAME" />
<login userName="ServerUserName" password="ServerPassword" />

But it should be :

<url value="jdbc:mysql://IPADDRESS/DBBASENAME" />
<login userName="MYSQLUserName" password="MYSQLPassword" />

Answer

Rick James picture Rick James · Nov 14, 2017

Change it in my.cnf, then restart mysqld.

Better yet, put it in a file under /etc/mysql/mariadb.conf.d/, and specify the section:

[mysqld]
max_allowed_packet = 1073741824

What you did (SET) went away when you restarted. Even so, it only applied to connections that logged in after doing the SET.