MySQL server has gone away解决办法
发布:smiling 来源: PHP粉丝网 添加日期:2014-10-14 14:48:58 浏览: 评论:0
数据库出现MySQL server has gone away这种问题根据我的经验,一是你程序向一个字段或一条语句中用超大的数据存储,但你的mysql的max_allowed_packet又没设置这么大的参考,所在就出现了这样的问题。
先要确认是不是你的空间商出问题,如果你是虚拟空间的话就先如下操作:
1、虚拟主机用户请联系空间商确认 MySQL 服务器是否正常,或者你的程序在运行过程中消耗了太多的服务器资源,请联系空间商进行确认;
2、独立主机用户请优化你的 MySQL 的配置,检查 MySQL 的运行情况,适当的时候增加服务器的配置。
3、因为执行动作过多,造成 MySQL 连接超时,如果是独立主机请修改 MySQL的配置文件中的 wait_timeout 这个值设置大一点.
如果你是自己的服务器可以如下操作:
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 参数的作用是,用来控制其通信缓冲区的最大长度.
主要可能是因为以下几种原因:
一种可能是发送的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及其解决.
Introduction
Here is a step by step guide, equally valid for your Linux server as well as any local Windows MySQL installation you may be using as a trial installation along with your local Drupal installation.
MySQL comes with a default configuration of the resources it is going to use, specified in "my.ini" (Windows) or "my.cnf" (Linux) during the installation of MySQL. In Windows this file is located by default at C:Program FilesMySQLMySQL Server X.Ymy.ini. In Linux this file is located at /etc/my.cnf to set global options, or /usr/local/var/mysql-data-dir/my.cnf to set server-specific options.
Resources allowed by the default configuration are normally insufficient to run a resource-intensive application. You must modify the following resource specifications if they are available in your original configuration file, or add them to the configuration file if they are not already specified (because some are not present by default):
Important: Remember to keep backup files before you do anything! You will also have to reload the MySQL service after making changes to these configuration files.
MyISAM specifications,代码如下:
- [mysqld]
- port = 3306
- socket = /tmp/mysql.sock
- skip-locking
- key_buffer = 384M
- max_allowed_packet = 64M
- table_cache = 4096
- sort_buffer_size = 2M
- read_buffer_size = 2M
- read_rnd_buffer_size = 64M
- myisam_sort_buffer_size = 64M
- thread_cache_size = 8
- query_cache_size = 32M
- InnoDB specifications
- --phpfensi.com
- innodb_buffer_pool_size = 384M
- innodb_additional_mem_pool_size = 20M
- innodb_log_file_size = 10M
- innodb_log_buffer_size = 64M
- innodb_flush_log_at_trx_commit = 1
- innodb_lock_wait_timeout = 180
Note:It is assumed here that you are using the InnoDB database tables, as Drupal is a resource intensive application. If you are not using the InnoDB database tables try to change this, in view of the fact that you are getting the Warning: MySQL server has gone away - apparently meaning that your setup is resource intensive. Convert MyISAM Tables to InnoDB.
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)
- ·MySQL server has gone away问题解决办法(2014-10-01)
- ·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)
- ·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)