can't connect to MySql from Java remotely

Posted January 6, 2015 4.1k views

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

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4739923 > 1048576). You can change this value on the server by setting the maxallowedpacket’ 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 maxallowedpacket = 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.


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.

1 answer

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

Submit an Answer