max_allowed_packet error

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.


Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

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 = 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.
Ryan Quinn
DigitalOcean Employee
DigitalOcean Employee badge
November 4, 2016

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.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel