MySQL server has gone away問題

description:
remember that your MySQL "max_allowed_packet" configuration setting (default 1MB)
mysql 默認最大能夠處理的是1MB
如果你在sql使用了大的text或者BLOB數據,就會出現這個問題。 php手冊上的註釋

When trying to INSERT or UPDATE and trying to put a large amount of text or data (blob) into a mysql table you might run into problems.
In mysql.err you might see:
Packet too large (73904)
To fix you just have to start up mysql with the option -O max_allowed_packet=maxsize
You would just replace maxsize with the max size you want to insert, the default is 65536


mysql手冊上說

Both the client and the server have their own max_allowed_packet variable, so if you want to handle big packets, you must increase this variable both in the client and in the server.

If you are using the mysql client program, its default max_allowed_packet variable is 16MB. To set a larger value, start mysql like this:

shell> mysql --max_allowed_packet=32M That sets the packet size to 32MB.

The server's default max_allowed_packet value is 1MB. You can increase this if the server needs to handle big queries (for example, if you are working with big BLOB columns). For example, to set the variable to 16MB, start the server like this:

shell> mysqld --max_allowed_packet=16M You can also use an option file to set max_allowed_packet. For example, to set the size for the server to 16MB, add the following lines in an option file:

[mysqld]max_allowed_packet=16M

使用mysql做數據庫還原的時候,由於有些數據很大,會出現這樣的錯誤:The MySQL Server returned this Error:MySQL Error Nr.2006-MySQL server has gone away。我的一個150mb的備份還原的時候就出現了這錯誤。解決的方法就是找到mysql安裝目錄,找到my.ini文件,在文件的最後添加:max_allowed_packet = 10M(也可以設置自己需要的大小)。 max_allowed_packet 參數的作用是,用來控制其通信緩衝區的最大長度。
發佈了2 篇原創文章 · 獲贊 0 · 訪問量 2159
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章