Packet for query is too large
数据库:mysql5.6
framework: play framework 1.2.4
近日处理批量数据的insert,update,涉及的保存更新sql大概有18w。我的操作如下:
1)每次取1000条数据进行相关逻辑判断,以及需要的保存操作;
2)每100条sql做一次transaction.commit。
今天在执行过程中,保存含有些Blob字段的数据表时,报错如下:
Packet > ). You can change this value on the server by setting the max_allowed_packet ' variable.
关于max_allowed_packet, 官方解释 如下:
The maximum size of one packet or any generated/intermediate string, or any parameter sent by the mysql_stmt_send_long_data() C API function. The default is 4MB as of MySQL 5.6.6, 1MB before that.
The packet message buffer is initialized to net_buffer_length bytes, but can grow up to max_allowed_packet bytes when needed. This value by default is small, to catch large (possibly incorrect) packets.
You must increase this value if you are using large BLOB columns or long strings. It should be as big as the largest BLOB you want to use. The protocol limit for max_allowed_packet is 1GB. The value should be a multiple of 1024; nonmultiples are rounded down to the nearest multiple.
大致上看,max_allowed_packet是字符串缓冲区的最大长度。MySQL5.6.6默认值是4MB,之前版本默认值是1MB。如果我们使用blob类型或者其它常字符串类型字段,那么必须将max_allowed_packet值设置成我们需要的最大长度。
设置方式 官方 ,具体如下:
1)查看自己的max_allowed_packet,进入mysql console:mysql>show VARIABLES like '%max_allowed_packet%';
2.1)修改配置文件方式:unix,mac,linux的配置文件
my.cnf,windows的配置文件是my.cnf。配置中添加"
max_allowed_packet
=xxx"
,xxx为需要设置的长度,单位默认是比特。比如:max_allowed_packet=1024*1024,即max_allowed_packer设置成1MB。
2.2)命令行配置:
set global max_allowed_packet = 1024*1024;
3)最后都需要重启mysql服务才能生效。
以上是我查到了关于mysql设置选项max_allowed_packet的相关,我本地试过用2.2方式修改,成功了。
但是后来我发现我真正的问题是另一个字段设计上的遗漏,就是我给一张表加了2个blob的字段,对应到数据库中是longtext类型。这两个字段的值相同,然后没条数据在保存的时候,都会向mysql字符缓冲区中放入这两个blob,这才导致了数据packet过大,超过buffer限制。后来我删了2个字段中的那个测试字段,job妥妥的执行下去了,也没有卡住,或者越跑越慢的现象。
总之,又学到了一点。如果有什么理解错的,务必请帮忙纠正,谢谢。
最后,贴一张上面的报错截图:

Packet for query is too large的更多相关文章
- mysql Packet for query is too large (1185 > 1024)异常
注:最近mysql一直提示如下错误 Packet for query is too large (1185 > 1024). You can change this value on the s ...
- Packet for query is too large(1767212 > 1048576)mysql在存储图片时提示图片过大
原网址:http://blog.csdn.net/bigbird2012/article/details/6304417 错误现象:Packet for query is too large(1767 ...
- nested exception is com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1044 > 1024
HTTP Status 500 - type Exception report message description The server encountered an internal error ...
- MySQL5中大数据错误:Packet for query is too large (****** > ******). You can change this value on the server by setting the max_allowed_packet' variable.;
使用的MySQL数据库版本:5.5 插入或更新字段有大数据时(大于1M),会出现如下错误: ### Cause: com.mysql.jdbc.PacketTooBigException: Packe ...
- Mysql插入内容过长(Packet for query is too large)
原文:Mysql插入内容过长(Packet for query is too large) 这个以前一直没有碰到过,一次性向Mysql数据库插入内容过长的话会出现这个问题,解决办法就是在Mysql配置 ...
- Packet for query is too large (84 > -1).
windows下的resin配置连接mysql,常用的安全的做法是将数据库信息配置到conf目录下的resin.xml文件中. 因为resin连接mysql不是必须的,所以resin本身没有提供mys ...
- Mysql数据中Packet for query is too large错误的解决方法
有时,程序在连接mysql执行操作数据库时,会出现如下类似错误信息: Packet for query is too large (4230 > 1024). You can change th ...
- com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024)
### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024). You ...
- 服务器的日志一直报Packet for query is too large (7632997 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.的解决方法
服务器的日志一直报Packet for query is too large (7632997 > 4194304). You can change this value on the serv ...
- Packet for query is too large (5,145 > 1,024). You can change this value on the server by setting the 'max_allowed_packet' variable.
错误 在使用Mybatis generator时提示MySQL写入过大 Packet for query is too large (5,145 > 1,024). You can change ...
随机推荐
- R语言数据管理(二):模式与类
最常用的4种数据类型是数值型(numeric).字符型(character)(字符串).日期型(Date)或POSIXct(基于日期的).逻辑型(logical)(TRUE或FALSE). 变量中 ...
- java并发实现原子操作
来自<java并发编程的艺术>.只是方便自己以后查找. 处理器如何实现原子操作 32位IA-32处理器使用基于对缓存加锁或总线加锁的方式来实现多处理器之间的原子操作.首先处理器会自动保证基 ...
- 《程序员代码面试指南》第二章 链表问题 在单链表和双链表中删除倒数第K个节点
题目 在单链表和双链表中删除倒数第K个节点 java代码 /** * @Description:在单链表和双链表中删除倒数第K个节点 * @Author: lizhouwei * @CreateDat ...
- 【leetcode刷题笔记】Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrin ...
- android OTA升级包制作【转】
本文转载自:http://www.thinksaas.cn/topics/0/445/445670.html 0.签名 java -Xmx2048m -jar out/host/linux-x86/f ...
- javascript数字时钟
<html> <head> <script type="text/javascript"> function startTime() { var ...
- Spring Cloud之服务治理(注册发现)
服务治理SpringCloud Eureka 什么是服务治理 在传统rpc远程调用中,服务与服务依赖关系,管理比较复杂,所以需要使用服务治理,管理服务与服务之间依赖关系,可以实现服务调用.负载均衡.容 ...
- oracle 从select的结果update其他表
update a set a.id=(selelct b.id from temp b where b.line = a.line) where a.line = (select line from ...
- CDH- 测试mr
cdh的mr样例算法的jar包在 [zc.lee@ip---- hadoop-0.20-mapreduce]$ pwd /opt/cloudera/parcels/CDH--.cdh5./lib/ha ...
- javaScript-基础篇(一)
1.如何插入JS 使用<script>标签在HTML网页中插入JavaScript代码.注意, <script>标签要成对出现,并把JavaScript代码写在<scri ...