can't connect to MySql from Java remotely

January 6, 2015 2k views

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 maxallowedpacket' 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 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.

3 comments
  • You confirmed that the option is being read correctly before restarting mysql:

    my_print_defaults --mysqld | grep max_allowed_packet
    
  • it shows

    my_print_defaults: unknown option '--mysqld' 
    
  • @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.

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

Have another answer? Share your knowledge.