ERROR 2006 (HY000) at line 1: MySQL server has gone away

前端 未结 6 605
有刺的猬
有刺的猬 2021-02-05 09:07

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

相关标签:
6条回答
  • 2021-02-05 09:22

    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
    
    0 讨论(0)
  • 2021-02-05 09:25

    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.

    0 讨论(0)
  • 2021-02-05 09:33

    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

    0 讨论(0)
  • 2021-02-05 09:40

    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".

    0 讨论(0)
  • 2021-02-05 09:41

    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;
    
    0 讨论(0)
  • 2021-02-05 09:44

    I just found that this error was happening because I was using "windows power-shell" instead of command prompt :)) Solved!!!

    0 讨论(0)
提交回复
热议问题