`

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1078 > 1024

 
阅读更多

报错:

com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1078 > 1024). You can change this value on the server by setting the max_allowed_packet' variable.
	at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3678) ~[mysql-connector-java-5.1.45.jar:5.1.45]
	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2509) ~[mysql-connector-java-5.1.45.jar:5.1.45]
	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2680) ~[mysql-connector-java-5.1.45.jar:5.1.45]
	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2484) ~[mysql-connector-java-5.1.45.jar:5.1.45]
	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858) ~[mysql-connector-java-5.1.45.jar:5.1.45]
	at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1197) ~[mysql-connector-java-5.1.45.jar:5.1.45]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3051) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.filter.FilterAdapter.preparedStatement_execute(FilterAdapter.java:1080) ~[druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.wall.WallFilter.preparedStatement_execute(WallFilter.java:619) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.filter.FilterEventAdapter.preparedStatement_execute(FilterEventAdapter.java:440) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3049) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:167) [druid-1.1.8.jar:1.1.8]
	at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:498) [druid-1.1.8.jar:1.1.8]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
	at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) [mybatis-3.4.6.jar:3.4.6]
	at com.sun.proxy.$Proxy139.execute(Unknown Source) [na:na]

 原因:

MySQL根据配置文件会限制Server接受的数据包大小。有时候大的插入和更新会受 max_allowed_packet 参数限制,导致大数据写入或者更新失败。

解决:

进入数据库,执行:show VARIABLES like '%max_allowed_packet%';

太小导致出错。

在linux下,进入到mysql安装目录下,进入到:

/usr/local/mysql,找到my.cnf,增加一行

max_allowed_packet = 20M

如果没找到my.cnf,进入跟路径下:cd /  使用命令搜索:find -name my.cnf

重启mysql:service mysql restart

执行查看:show VARIABLES like '%max_allowed_packet%';


 执行代码,不报错误了。
 

 

  • 大小: 5.7 KB
  • 大小: 12.8 KB
分享到:
评论

相关推荐

    com.mysql.jdbc.PacketTooBigException: Packet for query is too large (11087 > 102

    本文将深入探讨“com.mysql.jdbc.PacketTooBigException: Packet for query is too large (11087 > 102)”这一异常,分析其原因,并提供相应的解决方案。 `com.mysql.jdbc.PacketTooBigException` 是MySQL JDBC驱动...

    Mysql的longblob字段插入数据问题解决

    想改变这个问题,需要注意几点: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (2054817 > 1048576). You can change this value on the server by setting the max_allowed_packet’ ...

    88秒插入1000万条数据到MySQL数据库表的操作方法

    com.mysql.jdbc.PacketTooBigException: Packet for query is too large (4232009 > 4194304). You can change this value on the server by setting the max_allowed_packet’ variable. 出现上面的错误是因为...

    MySQL Packet for query is too large 问题及解决方法

    Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1354 > 1024). You can change this value on the server  by setting the max_allowed_packet’ variable  MySQL根据配置...

    MySQL批量插入和唯一索引问题的解决方法

    MySQL批量插入问题 ...nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (5677854 > 1048576). You can change this value on the server by setting the max_allowed_pac

    启动报错:验证加密狗无效 error:1001-mysql参数导致.docx

    nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1280 > 1024). You can change this value on the server by setting the max_allowed_packet' variable ``` - **...

    MySQL中文参考手册.chm

    <br/>3.6.3 登录支持 <br/>3.6.4 扩展的登录支持 <br/>4 安装 MySQL <br/>4.1 怎样获得MySQL <br/>4.2 MySQL支持的操作系统 <br/>4.3 使用MySQL哪个版本 <br/>4.4 怎样和何时发布更新版本 <br/>4.5 安装布局 <br/>...

    MYSQL

    <br>18.2.3 Host '...' is blocked错误 <br>18.2.4 Out of memory错误 <br>18.2.5 Packet too large错误 <br>18.2.6 The table is full错误 <br>18.2.7 Commands out of sync in client错误 <br>18.2.8 Ignoring ...

    MySQL中文参考手册

    * 1 MySQL的一般的信息 o 1.1 什么是MySQL? o 1.2 关于本手册 + 1.2.1 本手册中使用的约定 o 1.3 MySQL的历史 o 1.4 MySQL的主要特征 o 1.5 MySQL稳定性? o 1.6 顺应2000年 o 1.7 SQL一般信息和教程 o ...

Global site tag (gtag.js) - Google Analytics