peterQ
By:
peterQ

max_allowed_packet error

November 4, 2016 137 views
Java MySQL Ubuntu 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.

Thanks

2 Answers
peterQ November 5, 2016
Accepted Answer

SOLUTION:
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 = 0.0.0.0 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.

Have another answer? Share your knowledge.