第一句子网 - 唯美句子、句子迷、好句子大全
第一句子网 > MySQL server has gone away解决办法【MySQL】

MySQL server has gone away解决办法【MySQL】

时间:2023-11-06 00:58:39

相关推荐

MySQL server has gone away解决办法【MySQL】

数据库|mysql教程

,空间,用户

数据库-mysql教程

app聊天源码,ubuntu卸载秘钥,怎么判断tomcat正确执行,爬虫火蝾螈,对象和数组php,青岛seo行者seo08lzw

先要确认是不是你的空间商出问题,如果你是虚拟空间的话就先如下操作

商业版网站源码,ubuntu和主机磁盘,tomcat缓存配置的作用,爬虫如何暂停,php 在线执行环境,河南百度seo推广能带来客户吗lzw

1、虚拟主机用户请联系空间商确认 MySQL 服务器是否正常,或者你的程序在运行过程中消耗了太多的服务器资源,请联系空间商进行确认;

发卡个人平台源码,uos应用商店ubuntu,北京金融局爬虫,php存储html,seo小跟班lzw

2、独立主机用户请优化你的 MySQL 的配置,检查 MySQL 的运行情况,适当的时候增加服务器的配置。

3、因为执行动作过多,造成 MySQL 连接超时,如果是独立主机请修改 MySQL 的配置文件中的 wait_timeout 这个值设置大一点。

如果你是自己的服务器可以如下操作

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

解决方案:

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

wait_timeout=2880000

interactive_timeout = 2880000

关于两个变量的具体说明可以google或者看官方手册。如果不能修改f,则可以在连接数据库的时候设置

CLIENT_INTERACTIVE,比如:

sql = “set interactive_timeout=24*3600”;

mysql_real_query(…)

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

解决方案:

在f文件中添加或者修改以下变量:

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

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

主要可能是因为以下几种原因:

一种可能是发送的SQL语句太长,以致超过了max_allowed_packet的大小,如果是这种原因,你只要修改f,加大max_allowed_packet的值即可。

还有一种可能是因为某些原因导致超时,比如说程序中获取数据库连接时采用了Singleton的做法,虽然多次连接数据库,但其实使用的都是同一个连接,而且程序中某两次操作数据库的间隔时间超过了wait_timeout(SHOW STATUS能看到此设置),那么就可能出现问题。最简单的处理方式就是把wait_timeout改大,当然你也可以在程序里时不时顺手mysql_ping()一下,这样MySQL就知道它不是一个人在战斗。

解决MySQL server has gone away

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

解决方案:

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

wait_timeout=2880000

interactive_timeout = 2880000

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

代码如下 复制代码

sql = “set interactive_timeout=24*3600”;

mysql_real_query(…)

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

解决方案:

在f文件中添加或者修改以下变量:

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 “f” (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/f to set global options, or /nokia/c7/ /usr/local/var/mysql-data-dir/f 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

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 .

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。