ERROR 2006 (HY000) at line 1: MySQL server has gone away
I am facing the same problem. I am trying to restore mysqldump file to my machine. The file have size of 2.7 MB
Under [mysqld]
I have tried the following:
max_allowed_packet = 2096M
restarted mysqld and it did not work, however what worked for me is to set max_allowed_packet
globally from command line and then run the export from dump, it went through without any issues.
You can start from smaller packet size depending on database, I also did reimport my database with same size.
For Export:-
mysqldump --opt --user=confluenceUser --password='<passwd>' --max_allowed_packet=2147483648 confluencedb | gzip > confluencedb.sql.gz
For Import:-
mysql> SET GLOBAL max_allowed_packet=2147483648;
Query OK, 0 rows affected, 1 warning (0.00 sec)
zcat confluence.sql.gz | mysql -uconfluence -p<passwd> confluencedb
I had the same issue while restoring a bigger table: "SQL Fehler (2006): MySQL server has gone away".
Solution: Used smaller queries. Do not export big queries with comma separated rows. Changed it to single "INSERT" or "REPLACE" per row.
Change 3 settings in my.cnf file
Under [mysqld]
max_allowed_packet = 64M
wait_timeout = 6000
Under [mysqldump]
max_allowed_packet = 64M
That should fix it
This usually means that you have "incompatibilities with the current version of MySQL Server", see mysql_upgrade. I ran into this same issue and simply had to run:
mysql_upgrade --password
The documentation states that, "mysql_upgrade should be executed each time you upgrade MySQL".
Answers above can help, just adding my suggestion in addition as you can just bypass restrictions by directing using source command to import. As an alternative to mysql -u username -p database_name < file.sql, you can first login to mysql, select database and then import by source as below.
mysql -u username -p
mysql> use db_name;
mysql> source path-to/file.sql;
I just found that this error was happening because I was using "windows power-shell" instead of command prompt :)) Solved!!!