can't connect to MySql from Java remotely

I tried connecting to MySQL from Java, Class.forName(“com.mysql.jdbc.Driver”).newInstance(); java.sql.Connection conn1 = null; conn1 = DriverManager.getConnection(“jdbc:mysql://”,“mySQLusername”,“mySQLPassword”); conn1.close();

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.

at com.mysql.jdbc.MysqlIO.readPacket(

at com.mysql.jdbc.MysqlIO.doHandshake(

at com.mysql.jdbc.ConnectionImpl.coreConnect(

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(

at com.mysql.jdbc.ConnectionImpl.createNewIO(

at com.mysql.jdbc.ConnectionImpl.<init>(

at com.mysql.jdbc.JDBC4Connection.<init>(

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(

at java.lang.reflect.Constructor.newInstance(

at com.mysql.jdbc.Util.handleNewInstance(

at com.mysql.jdbc.ConnectionImpl.getInstance(

at com.mysql.jdbc.NonRegisteringDriver.connect(

at java.sql.DriverManager.getConnection(

at java.sql.DriverManager.getConnection(



I changed the max_allowed_packet = 16M, but it’s still showing the same error. I tried to connect to local mysql database and a friend’s machine on the intranet, it worked. Could that be a digitalOcean problem

Thanks in advance.

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

This question was answered by @gndo:

@rahulreddy - you can eliminate the double-dash in front of the group name mysqld. My version allows the double-dash as well as just the mysqld options group.

View the original comment