本文介绍了我的SQL:PacketTooBigException:查询的数据包太大(4,739,923> 65,535)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试连接到raspbery pi上的数据库.我已经在pi上下载了mysql,并且已经在pi上创建了一个数据库.我正在尝试使用驱动程序管理器进行连接.

I am trying to connect to a database on my raspbery pi. I have mysql downloaded on the pi and have created a database on there already. I am trying to use driver manager to connect.

这是我的代码:

public static void main(String[] args) {
    try {
        String host = "jdbc:mysql://scheduleit.duckdns.org:99/scheduleit";
        String uName = username;
        String uPass = password;
        Connection con = DriverManager.getConnection(host, uName, uPass);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}

我进入了配置文件,并将[mysqldump]的max_allowed_packet更改为32M.我浏览了其他配置文件,无法找到另一个max_allowed_pa​​cket字段进行编辑.另外,我使用了命令:mysql中的SET GLOBAL max_allowed_packet=32M;.

I have gone into the configuration files and changed the max_allowed_packet to 32M for [mysqldump]. I looked through the other configuration files and was unable to find another max_allowed_packet field to edit. Additionally, I have used the command: SET GLOBAL max_allowed_packet=32M; in mysql.

我很好奇的一件事是主机名是否错误.我使用端口99将ssh插入pi,但在连接DriverManager时可能使用了不同的端口吗? mysql的默认端口是3306,我尝试过该端口,但未建立连接.

One thing I was curious about was whether the hostname was wrong. I ssh into the pi using port 99, but perhaps I use a different port when connecting with a DriverManager? The default port for mysql is 3306 and I tried that, but wasn't getting a connection.

最后,我正在使用mariadb,据我所知,它实际上是mysql,因为我使用mysql -u root -p命令登录.任何帮助将非常感激.

Finally, I am using mariadb, which to my understanding is essentially mysql, since I log into using the mysql -u root -p command. Any help would be much appreciated.

推荐答案

MySQL服务器和客户端(在本例中为JDBC)都必须增加max_allowed_pa​​cket的设置.最大值实际上是客户端和服务器配置的较小.

Both the MySQL Server and the client (JDBC in this case) must increase their setting for max_allowed_packet. The max is effectively the lesser of the configuration of the client and the server.

对于服务器,请使用SET GLOBAL max_allowed_packet进行更改.您还应该在服务器的my.cnf文件中进行更改,因为在服务器重新启动时SET GLOBAL所做的更改会丢失.

For the server, you change this with SET GLOBAL max_allowed_packet. You should also change it in the server's my.cnf file because SET GLOBAL changes are lost when the server restarts.

对于客户机,如Michael上面所述,您可以在JDBC URL中将其指定为属性. JDBC属性除外,在 camelCase 中进行了拼写.

For the client, as Michael commented above, you can specify this as a property in the JDBC URL. Except JDBC properties are spelled in camelCase.

String host = "jdbc:mysql://scheduleit.duckdns.org:99/scheduleit?maxAllowedPacket=33554432";

请参见 https: //dev.mysql.com/doc/connector-j/5.1/zh-CN/connector-j-reference-configuration-properties.html 获取有关JDBC URL属性的更多文档.

See https://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-configuration-properties.html for more documentation on JDBC URL properties.

这篇关于我的SQL:PacketTooBigException:查询的数据包太大(4,739,923> 65,535)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:39