error: mysql server has gone away_科学网—MYSQL异常:General error: 2006 MySQL server has gone away - 孙鹏的博文...

在用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

我们查一下这里:

发现有这么一段话:

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的值问题,我们再看一下:

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

修改:C:ProgramDataMySQLMySQL Server 5.6my.ini

max_allowed_packet=4M

改为:

max_allowed_packet=100M

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

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

error: mysql server has gone away_科学网—MYSQL异常:General error: 2006 MySQL server has gone away - 孙鹏的博文..._第1张图片

转载本文请联系原作者获取授权,同时请注明本文来自孙鹏科学网博客。

链接地址:http://blog.sciencenet.cn/blog-419883-883665.html

上一篇:html5手机开发cookie的用法总结

下一篇:postgresql中比较real类型相等的正确方法

你可能感兴趣的:(error:,mysql,server,has,gone,away)