pakcettoobigexception

pcww981p  于 2021-06-19  发布在  Mysql
关注(0)|答案(2)|浏览(190)

这个问题在这里已经有答案了

com.mysql.jdbc.packettoobigexception(9个答案)
两年前关门了。
我正试图从spring启动应用程序连接到我的远程mysql数据库,但遇到了一段时间这个错误。
即使在增加了允许的最大数据包大小之后,我也得到了这个错误。

简单类测试连接

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCExample {

    public static void main(String[] argv) {

        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }

        Connection connection = null;

        try {

            connection = DriverManager.getConnection("jdbc:mysql://HOST:PORT/DB", "user", "password");

        } catch (SQLException e) {
            System.out.println("Connection Failed! Check output console");
            e.printStackTrace();
            return;
        }

        if (connection != null) {
            System.out.println("You made it, take control your database now!");
        } else {
            System.out.println("Failed to make connection!");
        }
    }
}

慰问:

Connection Failed! Check output console
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:578)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1014)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2190)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2221)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2016)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)

更新:
请注意,我已经增加了允许的最大数据包大小。当前大小为

mysql>  Select @@global.max_allowed_packet;
+-----------------------------+
| @@global.max_allowed_packet |
+-----------------------------+
|                   536870912 |
+-----------------------------+
1 row in set (0.31 sec)

mysql>
zzoitvuj

zzoitvuj1#

在mysql控制台中更改如下设置:

SET GLOBAL max_allowed_packet = 1024*1024*14;

然后再次尝试连接
更新:你可以这样检查thread:how to 更改允许的最大\u数据包大小
希望这对你有帮助

eivnm1vs

eivnm1vs2#

您需要设置服务器中允许的最大数据包大小以避免此错误。设置参数后,需要重新启动服务器。我不知道你正在使用的版本,所以请参阅下面的详细解释链接。
https://dev.mysql.com/doc/refman/8.0/en/packet-too-large.html

相关问题