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

報錯:java

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]

緣由:mysql

MySQL根據配置文件會限制Server接受的數據包大小。有時候大的插入和更新會受 max_allowed_packet 參數限制,致使大數據寫入或者更新失敗。linux

解決:sql

進入數據庫,執行:show VARIABLES like '%max_allowed_packet%';數據庫

過小致使出錯。apache

在linux下,進入到mysql安裝目錄下,進入到:mybatis

/usr/local/mysql,找到my.cnf,增長一行大數據

max_allowed_packet = 20Mui

若是沒找到my.cnf,進入跟路徑下:cd /  使用命令搜索:find -name my.cnfthis

重啓mysql:service mysql restart

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

執行代碼,不報錯誤了。

相關文章
相關標籤/搜索