Getting MYSQL Error: “Error Code: 2006 - MySQL ser

2019-02-04 09:12发布

I am getting following error, when I try to import MYSQL database:

Error Code: 2013 - Lost connection to MySQL server during queryQuery:
Error Code: 2006 - MySQL server has gone away

Can someone let me know what is wrong?

11条回答
可以哭但决不认输i
2楼-- · 2019-02-04 09:24

there are many reason that this issue is happening to you, here you can find all of the possible reasons, personally I've been struggling with the packet size but I've updated my my.ini file but before to do that, I've checked the max_allowed_packet variable that had given me 1048576B = 1MB and I've updated to 5MB. show variables where variable_name like '%packet%'

select 1048576 / 1024 / 1024

select 5242880 / 1024 / 1024

查看更多
Juvenile、少年°
3楼-- · 2019-02-04 09:27

Try following 2006 Error related fixes :

  • Server timed out and closed the connection. How to fix: check that wait_timeout variable in your mysqld’s my.cnf configuration file is large enough.

  • Server dropped an incorrect or too large packet. If mysqld gets a packet that is too large or incorrect, it assumes that something has gone wrong with the client and closes the connection. You can increase the maximal packet size limit by increasing the value of max_allowed_packet in my.cnf file.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-02-04 09:30

Investigation shows many solutions correctly talking about setting the max_allowed_packet and wait_timeout for mysql in my.cnf; small addendum that the default install of mysql on mac osx doesn't appear to include this file. You may first need to create it at /etc/my.cnf (this is only an issue if you're using the default install of mysql instead of a mamp stack or similar)

contents of /etc/my.cnf that corrected this issue for me below:

[mysqld]
max_allowed_packet= 64M
wait_timeout= 6000
查看更多
唯我独甜
5楼-- · 2019-02-04 09:31

It often happens, if your INSERT query is a too big single line statement with several rows.

查看更多
女痞
6楼-- · 2019-02-04 09:38

In MySQL 5.7 this error can be generated by a too large communication packet:

When a MySQL client or the mysqld server receives a packet bigger than max_allowed_packet bytes, it issues an ER_NET_PACKET_TOO_LARGE error and closes the connection. With some clients, you may also get a Lost connection to MySQL server during query error if the communication packet is too large.

A Packet in MySQL is:

A communication packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a master replication server to a slave.

You can found the doc here: DOC
You should try to set the max_allowed_packet to a bigger value (default value is 4MB) to solve if your SQL script is greater than this size. You can set this value within an Option File so you do not have to set it up each time.
On Microsoft Windows Vista and greater, you can set max_allowed_packet into the file
%PROGRAMDATA%\MySQL\MySQL Server 5.7\my.ini
or
%PROGRAMDATA%\MySQL\MySQL Server 5.7\my.cnf

where PROGRAMDATA = C:\ProgramData
More info (also for other S.O.) HERE

查看更多
迷人小祖宗
7楼-- · 2019-02-04 09:39

Try to restart mysql server. It`s possible that server is not working correctly but sql notifier displaying that is running, as well.

查看更多
登录 后发表回答