国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > MySQL > 正文

MySQL server has gone away解決辦法

2024-07-24 12:39:04
字體:
來源:轉載
供稿:網友

數據庫出現MySQL server has gone away這種問題根據我的經驗,一是你程序向一個字段或一條語句中用超大的數據存儲,但你的mysql的max_allowed_packet又沒設置這么大的參考,所在就出現了這樣的問題。

先要確認是不是你的空間商出問題,如果你是虛擬空間的話就先如下操作:

1、虛擬主機用戶請聯系空間商確認 MySQL 服務器是否正常,或者你的程序在運行過程中消耗了太多的服務器資源,請聯系空間商進行確認;

2、獨立主機用戶請優化你的 MySQL 的配置,檢查 MySQL 的運行情況,適當的時候增加服務器的配置。

3、因為執行動作過多,造成 MySQL 連接超時,如果是獨立主機請修改 MySQL的配置文件中的 wait_timeout 這個值設置大一點.

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

1、應用程序(比如PHP)長時間的執行批量的MYSQL語句,最常見的就是采集或者新舊數據轉化。

解決方案,在my.cnf文件中添加或者修改以下兩個變量,代碼如下:

  1. wait_timeout=2880000 
  2. interactive_timeout = 2880000 

關于兩個變量的具體說明可以google或者看官方手冊,如果不能修改my.cnf,則可以在連接數據庫的時候設置.

CLIENT_INTERACTIVE,比如:

  1. sql = "set interactive_timeout=24*3600"
  2. 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文件中添加或者修改以下兩個變量:

  1. wait_timeout=2880000 
  2. interactive_timeout = 2880000  

關于兩個變量的具體說明可以google或者看官方手冊,如果不能修改my.cnf,則可以在連接數據庫的時候設置CLIENT_INTERACTIVE,代碼如下:

  1. sql = "set interactive_timeout=24*3600"
  2. 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,代碼如下:

  1. [mysqld] 
  2. port = 3306 
  3. socket = /tmp/mysql.sock 
  4. skip-locking 
  5. key_buffer = 384M 
  6. max_allowed_packet = 64M 
  7. table_cache = 4096 
  8. sort_buffer_size = 2M 
  9. read_buffer_size = 2M 
  10. read_rnd_buffer_size = 64M 
  11. myisam_sort_buffer_size = 64M 
  12. thread_cache_size = 8 
  13. query_cache_size = 32M 
  14. InnoDB specifications 
  15. --Vevb.com 
  16. innodb_buffer_pool_size = 384M 
  17. innodb_additional_mem_pool_size = 20M 
  18. innodb_log_file_size = 10M 
  19. innodb_log_buffer_size = 64M 
  20. innodb_flush_log_at_trx_commit = 1 
  21. 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.

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泸水县| 云浮市| 海晏县| 西乡县| 九龙城区| 城口县| 贺州市| 樟树市| 精河县| 株洲市| 津市市| 格尔木市| 青阳县| 栖霞市| 石景山区| 象州县| 芦山县| 卓尼县| 霞浦县| 疏勒县| 吉隆县| 济宁市| 江川县| 营口市| 梓潼县| 响水县| 共和县| 肥城市| 明光市| 岚皋县| 武威市| 睢宁县| 满洲里市| 随州市| 丽水市| 姚安县| 清河县| 洪雅县| 永定县| 水城县| 武夷山市|