phpMyAdmin often fails on a large WordPress database: the upload stops, the page goes blank or you get a 504. The fix is to import the database over SSH instead, where no web upload limit or timeout applies. This guide shows how to upload the dump, import it with the mysql client or WP-CLI, and fix the errors large imports usually hit.
Quick answer: Upload the SQL file to the server, connect over SSH, and feed the file straight into MySQL. No PHP or web server sits in between, so nothing times out.
- Compress the dump locally with
gzipand upload it withscporrsync. - SSH in and read the database name, user and password from
wp-config.php. - Run
zcat backup_db.sql.gz | mysql -u USER -p DBNAME, orwp db import. - Count the tables and run
wp search-replaceif the domain changed. - Delete the dump from the server.
In this guide
- Before You Start
- Why phpMyAdmin Fails on Large SQL Files
- Step 1: Compress and Upload the SQL Dump
- Step 2: Find Your WordPress Database Credentials
- Step 3: Import the Dump with the mysql Client
- Or: Import with WP-CLI’s wp db import
- Step 4: Check the Import and Update URLs
- Step 5: Delete the Dump from the Server
- Fix Common MySQL Import Errors
- Frequently Asked Questions
- Next Steps

Before You Start
- Access: SSH login for the server, and the database name, user and password (they are in
wp-config.php). - The dump: your
.sqlor.sql.gzexport on your own computer. - Backup: importing replaces every table that has the same name as one in the dump. If the target site has data you need, export it first, for example with
wp db export ~/before-import.sql. - Time: a multi-gigabyte import can run for a long time. If SSH drops, the import stops, so use
screenortmuxif your server has them.
Why phpMyAdmin Fails on Large SQL Files
phpMyAdmin is a PHP app, so a big import has to pass through several layers: the web server, a PHP worker and finally MySQL. If any layer hits its limit, the import dies with a 504 Gateway Timeout or a blank white screen.
These limits usually break web imports:
- PHP upload limits:
upload_max_filesizeandpost_max_sizeare often capped at 64MB or 128MB, and raising them does not help with the time limits below. - PHP execution timeouts:
max_execution_timestops long-running scripts, often after 30, 60 or 300 seconds. A 1GB database takes several minutes to work through itsINSERTstatements. - Web server timeouts: the web server closes connections that wait too long, which shows up as a WordPress 504 gateway timeout error.
- Browser drops: if your connection blips during the upload, you can end up with half-imported tables.
Over SSH, the mysql client reads the file from the server’s own disk and streams it straight into the database. There is no HTTP request to time out.
Step 1: Compress and Upload the SQL Dump
On your own computer, compress the dump first. Plain-text SQL compresses very well, so the upload is much faster. Run this in your local terminal, in the folder that holds the file:
# Compress on your local machine before upload
gzip backup_db.sqlThis replaces backup_db.sql with backup_db.sql.gz.
Then, still in your local terminal, send the file to your home directory on the server. Replace username and your-server-ip with your SSH details:
# Transfer a compressed SQL file using SCP
scp ~/Downloads/backup_db.sql.gz username@your-server-ip:/home/username/scp shows a progress line that should reach 100%. If your connection is unstable or the dump is over 2GB, use rsync instead, because you can rerun it to resume an interrupted transfer:
# Resume-enabled transfer with rsync
rsync -avzP ~/Downloads/backup_db.sql.gz username@your-server-ip:/home/username/Keep the dump in your home directory, not inside the public web root, where anyone could download it.
Step 2: Find Your WordPress Database Credentials
From your local terminal, log in to the server and move to the WordPress root (the folder that contains wp-config.php). On a VPS that is often /var/www/html/; on Hostinger shared hosting it is ~/domains/yourdomain.com/public_html:
ssh username@your-server-ip
cd /var/www/html/Now, on the server, pull the database settings out of wp-config.php:
grep -E 'DB_NAME|DB_USER|DB_PASSWORD|DB_HOST' wp-config.phpYou should see four lines like these, with your own values:
define( 'DB_NAME', 'wp_production_db' );
define( 'DB_USER', 'wp_db_user' );
define( 'DB_PASSWORD', 'SecureRandomPassword_982#' );
define( 'DB_HOST', 'localhost' );If DB_HOST is something other than localhost, add -h and that host to the mysql commands below.
Step 3: Import the Dump with the mysql Client
The MySQL batch client reads SQL statements from standard input one at a time, so even a huge file does not need much memory. Run these commands on the server, using the database user and name from Step 2.
For an uncompressed .sql file:
mysql -u wp_db_user -p wp_production_db < /home/username/backup_db.sqlFor a compressed .sql.gz file, stream it through zcat so you never have to unpack it to disk:
# Stream compressed SQL directly into MySQL
zcat /home/username/backup_db.sql.gz | mysql -u wp_db_user -p wp_production_dbEnter the password from wp-config.php when asked. The terminal shows nothing while the import runs, so do not cancel it. When the prompt comes back with no message, the import worked. If it stops with a line starting ERROR, see Fix Common MySQL Import Errors below.
Or: Import with WP-CLI’s wp db import
If WP-CLI is installed, you can skip the credentials step. WP-CLI reads wp-config.php itself and passes the details to MySQL. Run it as the user that owns the site files rather than as root (for example sudo -u www-data wp ...), because commands that load WordPress run your plugin and theme code.
On the server, go to the WordPress root and run wp db import:
cd /var/www/html/
wp db import /home/username/backup_db.sql
# For a compressed dump, stream it instead:
zcat /home/username/backup_db.sql.gz | wp db import -When it finishes you should see a success line like this:
Success: Imported from '/home/username/backup_db.sql'.The same commands work in scripts. To schedule exports, see how to automate WordPress backups with WP-CLI and cron.
Step 4: Check the Import and Update URLs
On the server, count the imported tables:
mysql -N -u wp_db_user -p wp_production_db -e "SHOW TABLES;" | wc -lThe command prints one number. Run the same command on the old server; the two counts should match.
If the site moved from staging or a local copy, the database still contains the old address. Update it with WP-CLI’s search-replace, which also fixes PHP serialized data that a plain SQL replace would break. Run a dry run first from the WordPress root:
cd /var/www/html/
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables --dry-runThe dry run lists how many replacements each table would get and changes nothing. If the numbers look right, run it for real without --dry-run:
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tablesFor flags, edge cases and how to undo a bad replace, see the full guide to WP-CLI search-replace after a migration.
Step 5: Delete the Dump from the Server
The dump holds every user, order and setting in plain text. Once the site works, remove it from the server:
rm -f /home/username/backup_db.sql
rm -f /home/username/backup_db.sql.gzFix Common MySQL Import Errors
Large imports often run into server limits. These are the errors you are most likely to see.
Error: MySQL Server Has Gone Away (Error 2006)
This happens when a single row, such as a huge serialized page-builder layout in wp_posts, is bigger than MySQL’s packet size limit.
Raise the limit for your import by adding --max_allowed_packet to the command:
mysql --max_allowed_packet=512M -u wp_db_user -p wp_production_db < /home/username/backup_db.sqlIf the error continues, the server’s own limit is too low. On a VPS where you have root access, raise it in /etc/mysql/my.cnf or /etc/mysql/mysql.conf.d/mysqld.cnf. On shared hosting you cannot edit this file; ask your host’s support instead.
[mysqld]
max_allowed_packet = 512M
wait_timeout = 600
net_read_timeout = 600Restart MySQL to apply the change:
sudo systemctl restart mysqlError: Unknown Collation utf8mb4_unicode_520_ci
Moving a database from a newer MySQL or MariaDB server to an older one often fails here, because the older server does not know utf8mb4_unicode_520_ci (or MySQL 8’s utf8mb4_0900_ai_ci).
Replace both with the widely supported utf8mb4_unicode_ci before you import. sed -i edits the file in place, so it only works on an uncompressed .sql file; run gunzip on a .sql.gz first:
sed -i 's/utf8mb4_unicode_520_ci/utf8mb4_unicode_ci/g' /home/username/backup_db.sql
sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' /home/username/backup_db.sqlError: Foreign Key Check Violations
Some plugins, such as certain WooCommerce extensions, create tables with foreign key constraints (rules that link rows across tables). If the tables are imported in the wrong order, the import stops with a foreign key error.
Turn foreign key checks off for the import session only:
mysql --init-command="SET SESSION foreign_key_checks=0;" -u wp_db_user -p wp_production_db < /home/username/backup_db.sqlError: Access Denied for User (Error 1045)
The user name or password is wrong. Copy both exactly from wp-config.php. On shared hosting the user name usually starts with your account prefix (for example u123456789_), so type the full name, not just the part you chose.
Frequently Asked Questions
How do I see the progress of a large MySQL import over SSH?
Pipe the file through pv (Pipe Viewer). The mysql client has no progress bar, but pv shows throughput and an estimated time left. Installing it needs root, so this works on a VPS:
# Install pv on Ubuntu/Debian
sudo apt-get install pv
# Pipe the file through pv to see a real-time progress bar
pv /home/username/backup_db.sql | mysql -u wp_db_user -p wp_production_dbDoes importing overwrite my existing WordPress database?
Yes, for every table in the dump. Exports made with mysqldump or wp db export include a DROP TABLE IF EXISTS line before each table, so matching tables are replaced. Tables that are not in the dump stay as they were.
Can I export the database over SSH too?
Yes. Run mysqldump on the source server, from your home directory, to create a compressed export. Then download it with scp, the same way as Step 1 but with the source and destination swapped:
mysqldump -u wp_db_user -p wp_production_db | gzip > backup_db.sql.gzWhy does WP-CLI say “Error establishing a database connection” during import?
WP-CLI cannot reach the database with the details in wp-config.php. Check that MySQL is running (sudo systemctl status mysql on a VPS), and try 127.0.0.1 instead of localhost for DB_HOST to get around socket problems. More causes are in our guide to fix “Error establishing a database connection”.
What if the import freezes the whole server?
On a VPS with 1GB of RAM or less, a large import can trigger the Linux out-of-memory killer, which stops MySQL. Add a temporary 2GB swap file before importing so MySQL has room:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfileNext Steps
- Open the site and log in to wp-admin to check that posts, pages and settings came across.
- If the domain changed, finish the search-replace from Step 4 and clear any page cache.
- Make sure the dump is gone from the server and from your Downloads folder if you no longer need it.

