I'm trying to connect to an external mySQL DB through a Java program. When I attempt to connect, I obtain the following exception:
Exception in thread "main" 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:605)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1078)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2397)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2430)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2215)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:813)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:399)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:334)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Main.main(Main.java:48)
This is only for this external server. I was able to connect to a local server I set up without this issue at all.
I did some research on this and it talked about increasing my client max_allowed_packet size through a /etc/my.cnf file. I attempted to do this without any success. Would somebody be able to walk me through this as I can't even find the .cnf file. Is this even the right approach for a Java based connection?
Thanks in advance.
On the server, you must change your mysql configuration file. You will need to find it based on your operation system. See https://dev.mysql.com/doc/refman/5.6/en/option-files.html
You should not need to do anything on the client side to set this. Just send a large amount of data.