#2006 - MySQL server has gone away 问题解决方法

嵌入式学习之QT学习---14 QT跨平台运行之把QT程序交叉编译到ARM开发板 想要把qt工程放到开发板上运行,就需要用到交叉编译。由于qt是跨平台的,所以只需要换个编译器编译一下就可以。 以“定时器”的例子为例,在移植之前还需要进行一个准备工作,在windows下运行的时候,电脑屏幕很大,但是运行的窗口只有一点点大,开发板也有外接屏幕,如何让运行窗口自动适配开发板的外接屏幕呢?令其占满屏幕显示,而不是一小块。 第一步:需要设置一下,先给ui布局,如果不布局,控件就不会随着屏幕的大小的变化而变化。 第二步:利用代码来获取屏幕的大小,给widget.cpp文件下添加如下代码 #inclu 阅读详情

1、应用程序(比如PHP)长时间的执行批量的MYSQL语句。
最常见的就是采集或者新旧数据转化。

解决方案:

在my.ini文件中添加或者修改以下两个变量:
wait_timeout=2880000
interactive_timeout = 2880000


关于两个变量的具体说明可以google或者看官方手册。
如果不能修改my.cnf,则可以在连接数据库的时候设置CLIENT_INTERACTIVE,比如:
sql = "set interactive_timeout=24*3600";
mysql_real_query(...)


2、执行一个SQL,但SQL语句过大或者语句中含有BLOB或者longblob字段。
比如,图片数据的处理
解决方案


在my.cnf文件中添加或者修改以下变量:
max_allowed_packet = 10M  (也可以设置自己需要的大小)

max_allowed_packet 参数的作用是,用来控制其通信缓冲区的最大长度。

------------ 以下是网络搜索的资料 -------------------


也许其他人遇到这个问题,不一定是这儿的原因,那么,就把我在网上找到比较全面的分析放到下面:
有两篇,第一篇比较直观,第二篇比较深奥。
解决MySQL server has gone away 2009-01-09 16:23:22
来自:http://www.webjx.com/database/mysql-8817.html
今天遇到类似的情景,MySQL只是冷冷的说:MySQL server has gone away。
大概浏览了一下,主要可能是因为以下几种原因:
一种可能是发送的SQL语句太长,以致超过了max_allowed_packet的大小,如果是这种原因,你只要修改my.cnf,加大max_allowed_packet的值即可。
还有一种可能是因为某些原因导致超时,比如说程序中获取数据库连接时采用了Singleton的做法,虽然多次连接数据库,但其实使用的都是同一个连接,而且程序中某两次操作数据库的间隔时间超过了wait_timeout(SHOW STATUS能看到此设置),那么就可能出现问题。最简单的处理方式就是把wait_timeout改大,当然你也可以在程序里时不时顺手mysql_ping()一下,这样MySQL就知道它不是一个人在战斗。
解决MySQL server has gone away

1、应用程序(比如PHP)长时间的执行批量的MYSQL语句。最常见的就是采集或者新旧数据转化。

解决方案:

在my.cnf文件中添加或者修改以下两个变量:

wait_timeout=2880000
interactive_timeout = 2880000  
关于两个变量的具体说明可以google或者看官方手册。如果不能修改my.cnf,则可以在连接数据库的时候设置CLIENT_INTERACTIVE,比如:

sql = "set interactive_timeout=24*3600";
mysql_real_query(...)

2、执行一个SQL,但SQL语句过大或者语句中含有BLOB或者longblob字段。比如,图片数据的处理

解决方案:

在my.cnf文件中添加或者修改以下变量:

max_allowed_packet = 10M
(也可以设置自己需要的大小)

max_allowed_packet
参数的作用是,用来控制其通信缓冲区的最大长度

MySQL: 诡异的MySQL server has gone away及其解决
来自:http://fz9493.blog.sohu.com/38472203.html

jimmy | 15 三月, 2007 20:32

在Mysql执行show status,通常更关注缓存效果、进程数等,往往忽略了两个值:

Variable_name Value 
Aborted_clients 3792 
Aborted_connects 376


通常只占query的0.0x%,所以并不为人所重视。而且在传统Web应用上,query错误对用户而言影响并不大,只是重新刷新一下页面就OK了。最近的基础改造中,把很多应用作为service运行,无法提示用户重新刷新,这种情况下,可能就会影响到服务的品质。

通过程序脚本的日志跟踪,主要报错信息为“MySQL server has gone away”。官方的解释是:

The most common reason for the MySQL server has gone away error is that the server timed out and closed the connection.

Some other common reasons for the MySQL server has gone away error are:

You (or the db administrator) has killed the running thread with a KILL statement or a mysqladmin kill command.

You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.

A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.

You got a timeout from the TCP/IP connection on the client side. This may happen if you have been using the commands: mysql_options(..., MYSQL_OPT_READ_TIMEOUT,...) or mysql_options(..., MYSQL_OPT_WRITE_TIMEOUT,...). In this case increasing the timeout may help solve the problem.

You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).

You are using a Windows client and the server had dropped the connection (probably because wait_timeout expired) before the command was issued.

The problem on Windows is that in some cases MySQL doesn't get an error from the OS when writing to the TCP/IP connection to the server, but instead gets the error when trying to read the answer from the connection.

In this case, even if the reconnect flag in the MYSQL structure is equal to 1, MySQL does not automatically reconnect and re-issue the query as it doesn't know if the server did get the original query or not.

The solution to this is to either do a mysql_ping on the connection if there has been a long time since the last query (this is what MyODBC does) or set wait_timeout on the mysqld server so high that it in practice never times out.

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 A.1.2.9, “Packet too large”.

An INSERT or REPLACE statement that inserts a great many rows can also cause these sorts of errors. Either one of these statements sends a single request to the server irrespective of the number of rows to be inserted; thus, you can often avoid the error by reducing the number of rows sent per INSERT or REPLACE.

You also get a lost connection if you are sending a packet 16MB or larger if your client is older than 4.0.8 and your server is 4.0.8 and above, or the other way around.

It is also possible to see this error if hostname lookups fail (for example, if the DNS server on which your server or network relies goes down). This is because MySQL is dependent on the host system for name resolution, but has no way of knowing whether it is working — from MySQL's point of view the problem is indistinguishable from any other network timeout.

You may also see the MySQL server has gone away error if MySQL is started with the --skip-networking option.

Another networking issue that can cause this error occurs if the MySQL port (default 3306) is blocked by your firewall, thus preventing any connections at all to the MySQL server.

You can also encounter this error with applications that fork child processes, all of which try to use the same connection to the MySQL server. This can be avoided by using a separate connection for each child process.

You have encountered a bug where the server died while executing the query.



据此分析,可能原因有3:

1,Mysql服务端与客户端版本不匹配。

2,Mysql服务端配置有缺陷或者优化不足

3,需要改进程序脚本

通过更换多个服务端与客户端版本,发现只能部分减少报错,并不能完全解决。排除1。

对服务端进行了彻底的优化,也未能达到理想效果。在timeout的取值设置上,从经验值的10,到PHP默认的60,进行了多次尝试。而Mysql官方默认值(8小时)明显是不可能的。从而对2也进行了排除。(更多优化的经验分享,将在以后整理提供)

针对3对程序代码进行分析,发现程序中大量应用了类似如下的代码(为便于理解,用原始api描述):

$conn=mysql_connect( ... ... );

... ... ... ...

if(!$conn){ //reconnect

$conn=mysql_connect( ... ... );

}

mysql_query($sql, $conn);

这段代码的含义,与Mysql官方建议的方法思路相符[ If you have a script, you just have to issue the query again for the client to do an automatic reconnection. ]。在实际分析中发现,if(!$conn)并不是可靠的,程序通过了if(!$conn)的检验后,仍然会返回上述错误。

对程序进行了改写:

if(!conn){ // connect ...}

elseif(!mysql_ping($conn)){ // reconnect ... }

mysql_query($sql, $conn);

经实际观测,MySQL server has gone away的报错基本解决。

BTW: 附带一个关于 reconnect 的疑问,

在php4x+client3x+mysql4x的旧环境下,reconnet的代码:

$conn=mysql_connect(...) 可以正常工作。

但是,在php5x+client4x+mysql4x的新环境下,$conn=mysql_connect(...)返回的$conn有部分情况下不可用。需要书写为:

mysql_close($conn);

$conn=mysql_connect(...);

返回的$conn才可以正常使用。原因未明。未做深入研究,也未见相关讨论。或许mysql官方的BUG汇报中会有吧。

~~呵呵~~


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/brightsnow/archive/2009/03/17/3997705.aspx


description: 
remember that your MySQL "max_allowed_packet" configuration setting (default 1MB) 
mysql 默认最大能够处理的是1MB 
如果你在sql使用了大的text或者BLOB数据,就会出现这个问题。 php手册上的注释 

When trying to INSERT or UPDATE and trying to put a large amount of text or data (blob) into a mysql table you might run into problems. 
In mysql.err you might see: 
Packet too large (73904) 
To fix you just have to start up mysql with the option -O max_allowed_packet=maxsize 
You would just replace maxsize with the max size you want to insert, the default is 65536 


mysql手册上说 

Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server. 

If you are using the mysql client program, its default max_allowed_packet variable is 16MB. To set a larger value, start mysql like this: 

shell> mysql --max_allowed_packet=32M That sets the packet size to 32MB. 

The server's default max_allowed_packet value is 1MB. You can increase this if the server needs to handle big queries (for example, if you are working with big BLOB columns). For example, to set the variable to 16MB, start the server like this: 

shell> mysqld --max_allowed_packet=16M You can also use an option file to set max_allowed_packet. For example, to set the size for the server to 16MB, add the following lines in an option file: 

[mysqld]max_allowed_packet=16M 

使用mysql做数据库还原的时候,由于有些数据很大,会出现这样的错误:The MySQL Server returned this Error:MySQL Error Nr.2006-MySQL server has gone away。我的一个150mb的备份还原的时候就出现了这错误。解决的方法就是找到mysql安装目录,找到my.ini文件,在文件的最后添加:max_allowed_packet = 10M(也可以设置自己需要的大小)。 max_allowed_packet 参数的作用是,用来控制其通信缓冲区的最大长度

AI + 药物临床试验研发赛道 研究日期:2026-07-09 | 研究主题:AI + 药物临床试验研发赛道 | 聚焦岗位:Agent 平台架构师 / AI 工程架构师。 阅读详情

相关推荐

五子棋AI算法第一篇-我对谷歌Alphago的看法

最近Google宣布他们的围棋AI以5:0的战绩打败欧洲围棋三冠王。我一直对人工智能比较感兴趣,正好趁年前空闲的几天用JS写了一个五子棋的AI。其实很久以前就用自创的算法写过一个JAVA版的五子棋AI,不过棋力很不理想。这次用的是JS写的,所以无论任何平台上只要能打开网页的都可以玩。google爆出这个新闻之后,很多人觉得这是不是意味着电脑智商已经在人类之上了,围棋已经没有意义了之类的。甚至觉得这是

言川的博客 2万+

MySQL server has gone away 问题的解决方法

mysql出现ERROR : (2006, 'MySQL server has gone away') 的问题意思就是指client和MySQL server之间的链接断开了。 造成这样的原因一般是sql操作的时间过长,或者是传送的数据太大(例如使用insert ... values的语句过长, 这种情况可以通过修改max_allowed_packed的配置参数来避免,也可以在程序中将数据分批插...

优氪时 15万+

告别Modern Standby噩梦:Win11睡眠断网冻结的根源剖析与S3睡眠回归实战

本文深入剖析了Windows 11中Modern Standby(现代待机)模式导致睡眠后断网、系统冻结等问题的根源,指出其与硬件驱动、后台活动的兼容性矛盾。文章提供了通过修改注册表键值强制系统回归稳定S3睡眠状态的详细实战步骤,帮助用户彻底解决睡眠故障,实现可靠的远程访问与挂机任务。

weixin_29210727的博客 618

mysql gone away卡住_MySQL server has gone away 问题的解决方法

mysql出现ERROR : (2006, 'MySQL server has gone away') 的问题意思就是指client和MySQL server之间的链接断开了。造成这样的原因一般是sql操作的时间过长,或者是传送的数据太大(例如使用insert ... values的语句过长, 这种情况可以通过修改max_allowed_packed的配置参数来避免,也可以在程序中将数据分批插入)...

weixin_29496207的博客 1243

搭建PX4开发系统(Ubuntu 22.04)

本文是《从零开始学 PX4 无人机开发》系列第二篇,适合开发者在 Ubuntu 系统下快速搭建 PX4 编译与仿真环境,支持 QGroundControl、Gazebo、MAVSDK 等完整工具链。

qq_15856721的博客 4241

《解锁GCC版本选择的奥秘:从入门到精通》

GCC 版本的选择是一项复杂而关键的决策,犹如一场精心策划的战略布局,贯穿于软件开发的整个生命周期。从项目需求与兼容性的深度考量,到性能与稳定性的权衡抉择,再到硬件与系统适配的精准对接,每一个环节都紧密相连,相互影响。在游戏开发行业,对性能的极致追求促使开发者青睐较新的 GCC 版本,以实现更流畅的游戏体验和更震撼的视觉效果;科学计算领域则依赖于 GCC 版本对复杂数学运算的高效优化,以应对大规模数据处理的挑战;嵌入式开发行业因硬件资源的限制和对稳定性的严苛要求,通常选择经过长期验证的稳定版本;

zheng_ruiguo的专栏 1430

MySQL: server has gone away 问题的解决方法

mysql出现ERROR : (2006, 'MySQL server has gone away') 的问题意思就是指client和MySQL server之间的链接断开了。 造成这样的原因一般是sql操作的时间过长,或者是传送的数据太大(例如使用insert ... values的语句过长, 这种情况可以通过修改max_allowed_packed的配置参数来避免,也可以在程序中将数据分批插入)。 产生这个问题的原因有很多,总结下网上的分析: 原因一. MySQL 服务宕了 判断是否属于这.

走在搬砖的路上! 2万+

Chatbox使用指南

Chatbox使用指南

weixin_65289420的博客 2万+

mysql错误码:2006-MySQL server has gone away详解

mysql错误码:2006-MySQL server has gone away详解 1.背景 2.产生原因与解决方案一(mysql长连接) 2.1.mysql_ping与mysql长连接(此方案适用于解决代码开发中遇到的mysql错误码:2006—治标又治本) 重点参考有"//20190730 changlq add 修复mysql长连接长时间没有操作会被自动关闭的bug,错误信息:2006:M...

weixin_39568041的博客 1万+

Unity之如何实现哔哩哔哩直播弹幕游戏

什么是直播间互动?当我们使用哔哩哔哩进行直播或者观看视频时,我们可以通过接入哔哩哔哩提供的 直播&互动玩法SDK,让直播和视频可以与Unity3D游戏客户端或者游戏服务器进行互动。

TxNet 1556

使用 MATLAB/Simulink + Simscape Electrical 构建一个他励直流电机的启动与制动过程仿真模型

直流电机在工业控制、电动车辆、自动化设备中广泛应用。其中,他励直流电机(Separately Excited DC Motor)因其励磁绕组与电枢绕组分别供电,具有良好的调速性能和启动特性,常用于需要平稳启动和精确控制的场合。在实际应用中,电机的启动过程和制动过程对电网、机械系统以及电机本身都具有重要影响。因此,仿真分析他励直流电机的启动与制动特性,是电机控制设计的重要环节。本文将详细介绍如何使用构建一个他励直流电机的启动与制动过程仿真模型,并通过仿真分析其动态响应。本文详细介绍了如何使用构建一个。

amy_mhd的博客 234

MySQL导入sql文件,过大导致错误(2006 - MySQL server has gone away)

今天从MySQL导入sql文件的时候发现出现错误,查看日志发现报2006 - MySQL server has gone away 错误,出现这个的原因一般是传送的数据过大,解决的办法是: 查看通信缓冲区的最大长度: show global variables like 'max_allowed_packet'; 默认最大是1M,可以修改通信缓冲区的最大长度,修改为16M: se...

qq_44775798的博客 834

《QGIS快速入门与应用基础》191:渐变区间设置(等间隔/分位数)

深入解析QGIS中渐变符号化的核心环节——渐变区间设置,重点对比等间隔与分位数两种主流模式的原理与应用。作者指出,90%的渐变效果问题源于区间设置不当,强调必须先分析数据分布特征(通过统计面板查看直方图、极值等)再选择匹配模式。等间隔模式适用于均匀分布数据(如海拔、温度),将数值范围均等划分;分位数模式则针对偏态数据(如GDP、人口),保证每个区间要素数量相等。文章通过界面示意图、效果对比图和操作步骤详解,指导读者根据数据类型选择合适区间模式,并提醒常见避坑要点:社会经济数据禁用等间隔、分类数不超过8类。

LuckyHanMo的博客 324

mysql server has gone away 2006_#2006 - MySQL server has gone away 问题解决方法

1、应用程序(比如PHP)长时间的执行批量的MYSQL语句。最常见的就是采集或者新旧数据转化。解决方案:在my.ini文件中添加或者修改以下两个变量:wait_timeout=2880000interactive_timeout = 2880000关于两个变量的具体说明可以google或者看官方手册。如果不能修改my.cnf,则可以在连接数据库的时候设置CLIENT_INTERACTIVE,比如:...

weixin_32028323的博客 1405

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

#2006 - MySQL server has gone away 问题解决方法 (全) (转)

#2006 - MySQL server has gone away 问题解决方法 (全) (转)

asdfgh0077的博客 167

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

mysql报错 #2006 - MySQL server has gone away 问题解决方法

1、应用程序(比如使用Navicat)长时间的执行批量的MYSQL语句。 最常见的就是采集或者新旧数据转化。 解决方案: 在my.ini(或my.cnf)文件中添加或者修改以下两个变量: wait_timeout=2880000 interactive_timeout = 2880000 注意:这两个变量是要添加在【mysqlId】下面的,千万别填错了,添加在【client】下面是没有用的 关于两...

czczcz_的博客 1290

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

MySQL #2006 - MySQL server has gone away 问题解决方法

转自:http://www.cnblogs.com/bisonjob/archive/2009/08/18/1548611.html 在my.ini文件中添加或者修改以下两个变量: wait_timeout=2880000 interactive_timeout = 2880000在my.cnf文件中添加或者修改以下变量: max_allowed_packet = 10M  (也可以设置自

wowtous 861

#2006 - MySQL server has gone away 问题解决方法(转)

1、应用程序(比如PHP)长时间的执行批量的MYSQL语句。 最常见的就是采集或者新旧数据转化。 解决方案: 在my.ini文件中添加或者修改以下两个变量: wait_timeout=2880000 interactive_timeout = 2880000 关于两个变量的具体说明可以google或者看官方手册。 如果不能修改my.cnf,则可以在连接数据库的时候设置 C...

test 161

mac os #2006 - MySQL server has gone away 错误解决办法

MAC OS 本地开发PHP本地导入数据库可能有点大,24M记录的左右,导出成一个大sql文件,这个SQL文件内容是数据库结构+数据。 到入时就报#2006 - MySQL server has gone away! 一.打开:phpMyAdmin 找到localhost 服务器变量和设置: 二.修改下面几项: max_allowed_packet=500M wait_timeo

2366
上一篇: 當 mysqdump 遇到 Out of memory
下一篇: centos yum升级php
AlexJia2046
博客等级 码龄25年 98粉丝 211原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值