原因1. MySQL 服务宕了
判断是否属于这个原因的方法很简单,执行以下命令,查看mysql的运行时长

或者查看MySQL的报错日志,看看有没有重启的信息

如果uptime数值很大,表明mysql服务运行了很久了。说明最近服务没有重启过。 如果日志没有相关信息,也说明mysql服务最近没有重启过,可以继续检查下面几项内容。
原因2. 连接超时
如果程序使用的是长连接,则这种情况的可能性会比较大。 即,某个长连接很久没有新的请求发起,达到了server端的timeout,被server强行关闭。 此后再通过这个connection发起查询的时候,就会报错server has gone away

原因3. 进程在server端被主动kill
这种情况和情况2相似,只是发起者是DBA或者其他job。发现有长时间的慢查询执行kill xxx导致。

原因4. Your SQL statement was too large.
当查询的结果集超过 max_allowed_packet
也会出现这样的报错。定位方法是打出相关报错的语句。 用select * into outfile
的方式导出到文件,查看文件大小是否超过max_allowed_packet
,如果超过则需要调整参数,或者优化语句。
