Report this

What is the reason for this report?

can't connect to MySql from Java remotely

Posted on January 6, 2015

I tried connecting to MySQL from Java, Class.forName(“com.mysql.jdbc.Driver”).newInstance(); java.sql.Connection conn1 = null; conn1 = DriverManager.getConnection(“jdbc:mysql://mydomain.com/databaseName”,“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(MysqlIO.java:569)

at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1013)

at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2234)

at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2265)

at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2064)

at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:790)

at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44)

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

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

at com.mysql.jdbc.Util.handleNewInstance(Util.java:377)

at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:395)

at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:325)

at java.sql.DriverManager.getConnection(DriverManager.java:582)

at java.sql.DriverManager.getConnection(DriverManager.java:207)

at org.com.setuserv.TwitterSearchAPITweak.twitterDataToDB(TwitterSearchAPITweak.java:237)

at org.com.setuserv.TwitterSearchAPITweak.main(TwitterSearchAPITweak.java:32)

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.



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!

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.

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

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.