max_allowed_packet error

Posted November 4, 2016 8.1k views
MySQLJavaUbuntu 16.04

Hi all,
I’m new with DO and I got a LAMP 16.04 setup.
I’m creating a JavaFX desktop and trying to connect it to the MySQL server.
my.cnf has been edited - added max_allowed_packet = 1048576.
I also tested it by show variables like 'max_allowed_packet' in MySQL.

BUT, an error is still showing when I build the app.

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


These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

First, I’m a newbie so take my approach with that perspective.
Second, after spending HOURS searching and searching… One comment, yes one, suggested that the error is misleading. His issue was that the url was spelled wrong. So that got me thinking.

This article gave me the final key

So what I did was to check my access, ports and privileges and that’s how I found my issue.

  1. I checked mySQL for the available ports and confirmed that mySQL is listening to port 3306. I also did bind-address = in my.cnf file
  2. I also checked ufw ~$ sudo ufw status and add port 3306 $ sudo ufw allow 3306
  3. after this, it took me a few more hours and the answer was on the link above. Not the direct answer to the question, but one of the comments in it. Basically, I need to create a user (for the Javafx app) with a host name of “%” `mysql> GRANT ALL PRIVILEGES ON `database`.* TO 'mysqluser'@'%' - this can be done in my phpmyadmin too.

I don’t do a ton of stuff with Java but the error is showing that the packet size is still larger than the setting you set. I would look for a way to either reduce this on the client side or further increase it in my.cnf and restart MySQL.

Doing a bit of searching found this StackOverflow thread where one person also indicated that in some cases this error is misleading and they found a different solution.

  • Thanks @ryanpq. I’ve seen this thread and it did not work for me. I found my solution and I’ll post it in a few for others who have the same issue.

    • I faced this problem

      1. Packets out of order. Expected 0 received 45. Packet size=4739923
      2. SQLSTATE[HY000] [2006] MySQL server has gone away

      I am using laravel + mysql, my database and php code in different server, I added remote database access, but I faced same problem and tried increased packet size, dbuser permission and also add in config/database.php
      ‘options’ => array(

      but still face same problem. Please provide your solution, how did you solve your issue?