MySQL server has gone away问题解决办法
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-01 22:31:47 浏览: 评论:0
MySQL服务器出现MySQL server has gone away的原因有很多种,但最大的原因是我my.ini中配置问题导致的,下面我来介绍MySQL server has gone away问题解决办法.
执行一个SQL,但SQL语句过大或者语句中含有BLOB或者longblob字段,比如,图片数据的处理,都容易引起MySQL server has gone away.
今天遇到类似的情景,MySQL只是冷冷的说,MySQL server has gone away.
后来百度查找发现是mysql设置的问题.
原因1.MySQL 服务宕了
判断是否属于这个原因的方法很简单,执行以下命令,查看mysql的运行时长.
- $ mysql -uroot -p -e "show global status like 'uptime';"
- +---------------+-------+
- | Variable_name | Value |
- +---------------+-------+
- | Uptime | 68928 |
- +---------------+-------+
- 1 row in set (0.04 sec)或者查看MySQL的报错日志,看看有没有重启的信息
- $ tail /var/log/mysql/error.log
- 130101 22:22:30 InnoDB: Initializing buffer pool, size = 256.0M
- 130101 22:22:30 InnoDB: Completed initialization of buffer pool
- 130101 22:22:30 InnoDB: highest supported file format is Barracuda.
- 130101 22:22:30 InnoDB: 1.1.8 started; log sequence number 63444325509
- 130101 22:22:30 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
- 130101 22:22:30 [Note] - '127.0.0.1' resolves to '127.0.0.1';
- 130101 22:22:30 [Note] Server socket created on IP: '127.0.0.1'.
- 130101 22:22:30 [Note] Event Scheduler: Loaded 0 events
- 130101 22:22:30 [Note] /usr/sbin/mysqld: ready for connections.
- Version: '5.5.28-cll' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
如果uptime数值很大,表明mysql服务运行了很久了,说明最近服务没有重启过,如果日志没有相关信息,也表名mysql服务最近没有重启过,可以继续检查下面几项内容.
2.连接超时,如果程序使用的是长连接,则这种情况的可能性会比较大,即,某个长连接很久没有新的请求发起,达到了server端的timeout,被server强行关闭.
此后再通过这个connection发起查询的时候,就会报错server has gone away.
- $ mysql -uroot -p -e "show global variables like '%timeout';"
- +----------------------------+----------+
- | Variable_name | Value |
- +----------------------------+----------+
- | connect_timeout | 30 |
- | delayed_insert_timeout | 300 |
- | innodb_lock_wait_timeout | 50 |
- | innodb_rollback_on_timeout | OFF |
- | interactive_timeout | 28800 |
- | lock_wait_timeout | 31536000 |
- | net_read_timeout | 30 |
- | net_write_timeout | 60 |
- | slave_net_timeout | 3600 |
- | wait_timeout | 28800 |
- +----------------------------+----------+mysql> SET SESSION wait_timeout=5;
- ## Wait 10 seconds
- mysql> SELECT NOW();
- ERROR 2006 (HY000): MySQL server has gone away
- No connection. Trying to reconnect... --phpfensi.com
- Connection id: 132361
- Current database: *** NONE ***
- +---------------------+
- | NOW() |
- +---------------------+
- | 2013-01-02 11:31:15 |
- +---------------------+
- 1 row in set (0.00 sec)
3. 进程在server端被主动kill
这种情况和情况2相似,只是发起者是DBA或者其他job,发现有长时间的慢查询执行kill xxx导致.
- $ mysql -uroot -p -e "show global status like 'com_kill'"
- +---------------+-------+
- | Variable_name | Value |
- +---------------+-------+
- | Com_kill | 0 |
- +---------------+-------+
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 参数的作用是,用来控制其通信缓冲区的最大长度。
Tags: server has gone away
相关文章
- ·Navicat中MySQL server has gone away错误怎么办(2014-09-23)
- ·MySQL导入sql脚本错误:2006 - MySQL server has gone away(2014-09-24)
- ·WampServer修改Mysql密码的步骤(2014-09-25)
- ·General error: 2006 MySQL server has gone away(2014-10-02)
- ·sqlserver数据导出到MYSQL数据库方法(2014-10-04)
- ·mysql Starting MySQL..The server quit without updating PID file(2014-10-07)
- ·几种MySQL server has gone away解决办法(2014-10-08)
- ·Can t connect to local MySQL server through socket /tmp/mysql.sock(2014-10-08)
- ·解决MySQL server has gone away几种方法(2014-10-14)
- ·mysql Can’t connect to local MySQL server through socket ‘/var/lib/mysql/(2014-10-14)
- ·MySQL server has gone away解决办法(2014-10-14)
- ·is not allowed to connect to this MySQL server解决办法(2014-10-14)
- ·MySQL Slave同一server_id的冲突原因分析(2014-10-17)
- ·MySQL server has gone away原因分析与解决办法(2014-10-17)
- ·Can t connect to MySQL server 常见问题解决办法(2014-10-17)
- ·解决#2006 - MySQL server has gone away错误(2015-04-17)
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)