Getting an error while importing larger databases into mysql ?

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

Here is the simple trick to upload a larger database.

If you getting an error message when using PHPMyAdmin, switch to command line

Normal Command :

cd <path_to_sql_file> mysql -u root -p <database_name> < databe_name.sql

If the SQL file is zipped :

gunzip < database_name.sql.gz | mysql -u root -p<password> <database-name>

Add mysql password immediately after -p

If the above solutions results the same error message, then try to increase the max_allowed _ packet in mysql configuration file.

login to mysql using the below command in terminal

mysql -u root -p <enter_password >

After logged into mysql console , execute the below command.

Sets maximum allowed packet size to 128 MB

SET global max_allowed_packet=128*1024*1024

Sets maximum allowed packet size to 64 MB

SET global max_allowed_packet=64*1024*1024

Then exit the mysql editor


Execute import command again (mentioned above).

It's simple !