我在尝试连接数据库时遇到此问题。更改变量的值但仍然存在此错误
值mysql
@@max_allowed_packet
16777216
Java代码
Properties connProps = new Properties();
connProps.put("user", Config.DB_USER);
connProps.put("password", Config.DB_PASS);
this._conn = DriverManager.getConnection("jdbc:" + Config.DB_DBMS + "://" + Config.DB_HOST + ":"
+ Config.DB_PORT + "/" + Config.DB_NAME, connProps);
错误:
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.
修改我服务器上的my.cnf
文件
答案 0 :(得分:1)
jdbc客户端也有“maxAllowedPacket”设置。
你可以设置你的jdbc网址: JDBC:MySQL的://192.168.15.1/dbname了useUnicode =真安培;的characterEncoding = UTF-8和; maxAllowedPacket = 16777216
答案 1 :(得分:0)