General error: 2006 MySQL server has gone away

來源:互聯網
上載者:User

我自己人的經曆

先簡單介紹一下這個新手卡錄入後台,這個後台是提供給產品人員使用。可以向某個遊戲的某個特定分區批量錄入新手卡資訊,方便玩家擷取。後台設定的一次性最大錄入量為500。

先看日誌吧,報錯的內容和日誌的相同:

Error: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away


這個錯誤資訊很好的描述了是資料庫逾時引起的。以前聽前輩說過,應該是wait_timeout環境變數設定的有問題。可是查看後,發現wait_timeout設的好高啊,為28800,不應該出問題啊。無解。

頭回來後,訴說。頭笑而不語,讓我只看,別說話。

 代碼如下 複製代碼


show global variables;

set global wait_timeout = 120;


總結解決了,但很多MySQL server has gone away都與此問題無關了,都有和max_allowed_packet有關了

匯入資料庫的時候 SQLyog 報錯了

Error Code: 2006 – MySQL server has gone away

搜了下,說是max_allowed_packet (MySQL的一個參數)設定的值不夠大。

那我改下就行了 嘿嘿

In Windows:

In the MySQL server installation directory,
in my.ini file, add the following line under [mysqld] in SERVER SECTION.

max_allowed_packet = 16M

In Linux:

Copy the my-xxx.cnf file from /usr/share/mysql to /etc as my.cnf

xxx can be small, medium, large, huge … depending on the requirement.

 代碼如下 複製代碼

$ cp /usr/share/mysql/my-xxx.cnf /etc/my.cnf

In the my.cnf file, change the default
max_allowed_packet = 1M
to
max_allowed_packet = 16M

Save the file and restart MySQL server.

今天匯入.sql檔案時出現了Error Code: 2006 – MySQL server has gone away錯誤,原來是匯入的sql檔案大於系統預設的max_allowed_packet的值,查了很多修改設定檔的,但是沒有找到my.cfg檔案,修改其他檔案不管用,所以直接使用sql語句來修改:

 代碼如下 複製代碼

SET GLOBAL  max_allowed_packet=67108864;

就可以了,不是max_allowed_packet越大越好哦,大家可根據自己人情況來設定。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.