Inuar Tech

We provide software developmentĀ tailored to your business needs

ERROR 2006 (HY000): MySQL server has gone away using docker

Are you having problem importing your SQL dump? be it via command line or via container management console, here is the solution.

./mysql -u root -p my_db < file.sql
Enter password:
ERROR 2006 (HY000) at line 1: MySQL server has gone away

This is caused by SQL import file being too big or field carrying too much information, causing it to exceed the max_allowed_packet setting.

If you using docker-compose. create a file named my.cnf and use this config

max_allowed_packet=64M

then map it to your container.
...
volumes:
  - ./my.cnf:/etc/mysql/conf.d/my.cnf

then turn down the containers and up again.