数据库: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 的for else语句

    for中间不是break出来的,是正常循环完跳出循环的会执行else内的语句 while else语句也是如此 这个以前的常见语言没有,特此记录

  2. html post

    post请求对应的html页面 页面效果 html代码 <html> <body> <form method="post" > First na ...

  3. web开发工具网站

    配色 http://peise.net/tools/web/   http://retinaicon.com/   http://flattyshadow.com/     免费图片网站 https: ...

  4. Sql Server2008——存储过程编程简单例子

    主要介绍: 存储过程的定义方法及其使用方法. 实例介绍: 1 创建学生表Student create database Stu use Stu go CREATE TABLE Student ( Sn ...

  5. Data Structure Binary Tree: Print ancestors of a given binary tree node without recursion

    http://www.geeksforgeeks.org/print-ancestors-of-a-given-binary-tree-node-without-recursion/ #include ...

  6. P4240 毒瘤之神的考验

    题目 P4240 毒瘤之神的考验 神仙题\(emmm\) 前置 首先有一个很神奇的性质: \(\varphi(ij)=\dfrac{\varphi(i)\varphi(j)gcd(i,j)}{\var ...

  7. poj 3006 Dirichlet's Theorem on Arithmetic Progressions【素数问题】

    题目地址:http://poj.org/problem?id=3006 刷了好多水题,来找回状态...... Dirichlet's Theorem on Arithmetic Progression ...

  8. LINQ 学习路程 -- 查询操作 ThenBy & ThenByDescending

    IList<Student> studentList = new List<Student>() { , StudentName = } , , StudentName = } ...

  9. Spark- RDD简介

    Spark里面提供了一个比较重要的抽象——弹性分布式数据集(resilient distributed dataset),简称RDD.弹性:数据可大可小,可分布在内存或磁盘,当某台机器宕机时,能够按照 ...

  10. 翻译Lanlet2

    Here is more information on the basic primitives that make up a Lanelet2 map. Read here for a primer ...