This tutorial solves the error that appears when importing .sql files via the command line. Import .SQL File Error - MySQL server has gone away.
When we have to imported files .SQL big in one the date base, the classic method through phpMyAdmin it is not a very good solution. Most of the time we run into a “reqest timeout". Import .SQL Fillet Error - MySQL server has gone away.
The simplest is to connect SSH / console to the server that holds the database, let's upload the file .sql and then execute the specific command lines for import.
mysql -u db_user -p -h localhost db_name < /path/sql_file.sql
If after executing the command line and entering the database password you encounter the error: “ERROR 2006 (HY000) at line 1281: MySQL server has gone away", most of the time it is about exceeding a volume limit for the imported files.
It is very possible that in the standard configurations of MySQL, the volume limit established in "max_allowed_packet” should be smaller than that of the file you want to import into the database.
The simplest solution is to edit the file "my.cnf” and to establish a limit suitable for our needs. For example, if we want to import a file .SQL of 320 MB, then we edit the file "my.cnf”And we add the line:
max_allowed_packet=400M
After editing and saving, restart the mysql service on the server and restart the command line for import. Everything should work without Import .SQL File Error - MySQL server has gone away.