問題描述
當我嘗試獲取大型 SQL 文件(大型 INSERT
查詢)時出現此錯誤.
I get this error when I try to source a large SQL file (a big INSERT
query).
mysql> source file.sql
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 2
Current database: *** NONE ***
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 3
Current database: *** NONE ***
表中的任何內容都沒有更新.我試過刪除和取消刪除表/數據庫,以及重新啟動 MySQL.這些都不能解決問題.
Nothing in the table is updated. I've tried deleting and undeleting the table/database, as well as restarting MySQL. None of these things resolve the problem.
這是我的最大數據包大小:
Here is my max-packet size:
+--------------------+---------+
| Variable_name | Value |
+--------------------+---------+
| max_allowed_packet | 1048576 |
+--------------------+---------+
這里是文件大小:
$ ls -s file.sql
79512 file.sql
當我嘗試另一種方法時...
When I try the other method...
$ ./mysql -u root -p my_db < file.sql
Enter password:
ERROR 2006 (HY000) at line 1: MySQL server has gone away
推薦答案
max_allowed_packet=64M
將此行添加到 my.cnf
文件中解決了我的問題.
Adding this line into my.cnf
file solves my problem.
當列有很大的值時這很有用,這會導致問題,你可以找到解釋 此處.
This is useful when the columns have large values, which cause the issues, you can find the explanation here.
在 Windows 上,此文件位于:C:\ProgramData\MySQL\MySQL Server5.6"
On Windows this file is located at: "C:\ProgramData\MySQL\MySQL Server 5.6"
在 Linux (Ubuntu) 上:/etc/mysql
On Linux (Ubuntu): /etc/mysql
這篇關于ERROR 2006 (HY000): MySQL 服務器已經消失的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!