How to Fix 'MySQL Server Has Gone Away' and Import Large SQL Dumps

66 views
Short answer: Compress database dumps into .sql.gz before uploading via phpMyAdmin, or import directly through terminal CLI using mysql -u user -p db_name < dump.sql to bypass browser limits.

Overcome phpMyAdmin upload size restrictions and MySQL Error 2006 (Server Has Gone Away) when importing large database backups.

Before you start: Back up your site files and database and download the backup to your own computer. How to take a full backup

Quick reference

Default phpMyAdmin Limit Typically 50MB to 128MB
Best Compression .sql.gz or .zip (Reduces SQL filesize by ~80%)
SSH Import Command mysql -u dbuser -p dbname < backup.sql

Steps

  1. Compress the SQL Dump: Before uploading via phpMyAdmin, compress your .sql file into a .zip or .gz archive. phpMyAdmin automatically decompresses it on the server, allowing you to bypass upload limits.
  2. Increase PHP Upload Limits in cPanel:
    • Go to cPanel > Select PHP Version > Options.
    • Increase upload_max_filesize to 128M or 256M.
    • Set post_max_size equal to or higher than upload_max_filesize.
  3. Import via cPanel Terminal / SSH (Recommended for Dumps > 100MB):
    • Upload your database.sql file to your home directory via cPanel File Manager.
    • Open Terminal in cPanel (under Advanced) and run:
      mysql -u CPANELUSER_DBUSER -p CPANELUSER_DBNAME < database.sql
    • Enter the database user's password when prompted. The import will run in the background without HTTP timeout constraints.

Troubleshooting and tips

  • Packet Too Large Error: If an individual row or binary blob exceeds max_allowed_packet, the server drops the connection with "MySQL server has gone away". Export your SQL dump with --net_buffer_length=16384 or split the file.
  • Foreign Key Constraint Failures: Add SET FOREIGN_KEY_CHECKS=0; at the very top of your SQL dump file, and SET FOREIGN_KEY_CHECKS=1; at the bottom to avoid order-of-insertion errors.
Need more help? If you run into an error while following these steps, open a ticket with technical support and our team will look into it. Open a ticket
Was this article helpful?
No, I need more help
Didn't find your answer?
Under 3 minutes
Submit Support Ticket