数据库: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的更多相关文章

  1. 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 ...

  2. Packet for query is too large(1767212 > 1048576)mysql在存储图片时提示图片过大

    原网址:http://blog.csdn.net/bigbird2012/article/details/6304417 错误现象:Packet for query is too large(1767 ...

  3. 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 ...

  4. 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 ...

  5. Mysql插入内容过长(Packet for query is too large)

    原文:Mysql插入内容过长(Packet for query is too large) 这个以前一直没有碰到过,一次性向Mysql数据库插入内容过长的话会出现这个问题,解决办法就是在Mysql配置 ...

  6. Packet for query is too large (84 > -1).

    windows下的resin配置连接mysql,常用的安全的做法是将数据库信息配置到conf目录下的resin.xml文件中. 因为resin连接mysql不是必须的,所以resin本身没有提供mys ...

  7. Mysql数据中Packet for query is too large错误的解决方法

    有时,程序在连接mysql执行操作数据库时,会出现如下类似错误信息: Packet for query is too large (4230 > 1024). You can change th ...

  8. 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 ...

  9. 服务器的日志一直报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 ...

  10. 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 ...

随机推荐

  1. python字符串格式和编码与解码问题

    %c 转换成字符(ASCII码值,长度为一的字符串) %r 有线使用repr()函数进行字符串转换 %s 有线使用str()函数进行字符串转换 %d or %i 转换成有符号十进制数 %u 转换成无符 ...

  2. Python 3 面向对象进阶

    Python 3 面向对象进阶 一.    isinstance(obj,cls)和issubclass(sub,super) isinstance(obj,cls)检查是否obj是否是类 cls 的 ...

  3. 开发rsync启动脚本

    rsync rsync是类unix系统下的数据镜像备份工具——remote sync.一款快速增量备份工具 Remote Sync,远程同步 支持本地复制,或者与其他SSH.rsync主机同步.   ...

  4. codeforces 54A

    题意:收到礼物的规则为每个假日必收到一份礼物,每K天里至少收到一份礼物,求出N天中收到的礼物的最小数量. 思路:将N天根据假日所在天数分为一段段,当假日与假日之间间隔天数hol[i]>-hol[ ...

  5. 分享知识-快乐自己:Maven 无法加载 Oracle 数据库驱动源

    由于Oracle授权问题,Maven3不提供Oracle JDBC driver,为了在Maven项目中应用Oracle JDBC driver,必须手动添加到本地仓库. 手动添加到本地仓库需要本地有 ...

  6. POJ 2240 Arbitrage(Floyed-Warshall算法)

    题意:给出n种货币,m种兑换比率(一种货币兑换为另一种货币的比率),判断测试用例中套汇是否可行.(套汇的意思就是在经过一系列的货币兑换之后,是否可以获利.例如:货币i→货币j→货币i,这样兑换后,是否 ...

  7. Sed 命令详解 正则表达式元字符

    1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保存结果.默认情况下,所有的输出行都被打印到屏幕上. sed编辑器逐行处理文件(或输入),并将结果发送到屏幕.具体过程如下 ...

  8. Django 文件下载功能

    def file_download(request): con= MySQLdb.connect(host='192.168.xxx.xxx',user='root',passwd='xxxx',db ...

  9. python 链接sharepoint 2013 REST api

    import requests,simplejson from requests_ntlm import HttpNtlmAuth p1 = requests.get("http://you ...

  10. Mybatis异常_04_mapper.xml中不能使用小于号<、大于号>

    一.解决方法: 1.< 2.<![CDATA[ < ]]> 将小于号替换为上述代码即可. 二.参考资料 1.mybatis配置中sql莫名其妙报错,多半是条件中小于符号捣的鬼