数据库: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. 在网页中显示PDF文件及vue项目中弹出PDF

    1.<embed width="800" height="600" src="test_pdf.pdf"> </embed ...

  2. ARDUINO W5100 WebServer测试

    1.直接下载官方的enternet->WebServer代码 /* Web Server A simple web server that shows the value of the anal ...

  3. SQL性能优化常用语句(摘录网上)

    1.把trace文件导入到表中 , ) AS RowNumber,* into TableName FROM fn_trace_gettable('trace.trc', default) 2.查询C ...

  4. python基础4 ----字符编码

    python基础---字符编码 一.了解字符编码 1. 文本编辑器存取文件的原理(nodepad++,pycharm,word) 打开编辑器就打开了启动了一个进程,是在内存中的,所以在编辑器编写的内容 ...

  5. JETSON TK1 ~ 基于eclipse下开发ROS

    此文档是在PC端开发后移植到TK1,并非在TK1上安装eclipse 官方使用IDE开发的文档: http://wiki.ros.org/IDEs 一:安装eclipse 1.下载eclipse安装包 ...

  6. || and && 理解

    逻辑或(||): 只要第一个值的布尔值为false,那么永远返回第二个值. 逻辑或属于短路操作,第一个值为true时,不再操作第二个值,且返回第一个值. 逻辑与(&&): 只要第一个值 ...

  7. Ubuntu安装教程

    http://www.linuxdiyf.com/linux/13198.html 简易配置说明 磁盘分区,新分区的磁盘必须是未分配的, 到管理-磁盘管理下面查看磁盘是不是未分配的,如果已分配了,在磁 ...

  8. 【LeetCode】【动态规划】Generate Parentheses(括号匹配问题)

    描述 Given n pairs of parentheses, write a function to generate all combinations of well-formed parent ...

  9. [算法]Rotate Array

    You may have been using Java for a while. Do you think a simple Java array question can be a challen ...

  10. 算法(Algorithms)第4版 练习 1.5.22

    package com.qiusongde; import edu.princeton.cs.algs4.StdOut; import edu.princeton.cs.algs4.StdStats; ...