hillpig的个人博客分享 http://blog.sciencenet.cn/u/hillpig 畅想ing,思考ing,前行ing Email:bluevaley@gmail.com

博文

MYSQL异常:General error: 2006 MySQL server has gone away

已有 8142 次阅读 2015-4-19 19:02 |个人分类:postgresql|系统分类:科研笔记

在用php批量插入mysql数据时,如:

$pdo->beginTransaction(); // also helps speed up your inserts.

$stmt = $pdo->prepare ($sql);

try {

$stmt->execute($dataToInsert);

} catch (PDOException $e){

echo $e->getMessage();

}

$pdo->commit();


会遇到如下异常:

MYSQL异常:General error: 2006 MySQL server has gone away ph

我们查一下这里:

https://dev.mysql.com/doc/refman/5.0/en/gone-away.html

发现有这么一段话:

You can also get these errors if you send a query to the              server that is incorrect or too large. If              mysqld receives a packet that is too              large or out of order, it assumes that something has gone              wrong with the client and closes the connection. If you              need big queries (for example, if you are working with big              BLOB columns), you can              increase the query limit by setting the server's              max_allowed_packet              variable, which has a default value of 1MB. You may also              need to increase the maximum packet size on the client              end. More information on setting the packet size is given              in Section B.5.2.10, “Packet Too Large”.            

很显然,timeout肯定不是错误根源了,肯定是这个max_allowed_packet的值问题,我们再看一下:

https://dev.mysql.com/doc/refman/5.0/en/server-system-variables.html#sysvar_max_allowed_packet

发现,最大可以设置为1Gb。

修改:C:ProgramDataMySQLMySQL Server 5.6my.ini

max_allowed_packet=4M

改为:

max_allowed_packet=100M

或者你认为可以接受的最大的包大小,我们最大不到10MB,所以设置为100MB足够了。


加我私人微信,交流技术。





https://blog.sciencenet.cn/blog-419883-883665.html

上一篇:html5手机开发cookie的用法总结
下一篇:postgresql中比较real类型相等的正确方法
收藏 IP: 223.72.72.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-12 15:32

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部