phpMyAdmin on your hosting account accepts import files up to 50 MB, and even smaller files can time out halfway through. When your database is too big for phpMyAdmin, the reliable fix is to upload the file and import it over SSH with the mysql command. This guide walks you through it step by step, including compressed files, very long imports and the error messages you're most likely to see.
Why SSH works when phpMyAdmin doesn't
phpMyAdmin runs inside a web page. Your browser has to upload the whole file, then a PHP script has to read and run every line before the web server's time limit is up. Big files hit the upload limit, or the page simply gives up part way.
The mysql command-line tool skips all of that. It reads the file straight from your account's disk and streams it into the database, with no upload limit and no web timeout. A file that fails in phpMyAdmin after five minutes often imports over SSH in one or two.
What you need
- Shell access. Use Advanced > Terminal in cPanel (nothing to install), or SSH from your computer on port 22. If you don't see Terminal, or SSH logins are refused, open a ticket and ask for shell access to be turned on.
- An empty database and a user added to it with ALL PRIVILEGES. Create them in Databases > Database Wizard and note the full names, for example
username_shopandusername_shopuser, plus the password. - Your export file: a
.sqlfile, or a compressed.sql.gzor.zip. - Enough disk space for the file and the imported database. Check Disk Usage in the statistics on the right of the cPanel home page. An uncompressed
.sqlfile is roughly the size the database will be once imported.
Step 1: Upload the file to your account
Upload it to your home directory, not inside public_html. Anything in public_html can be downloaded by anyone who guesses the name, and a database dump contains your customers' details and password hashes.
- File Manager: in cPanel, go to Files > File Manager, click Home at the top left, then Upload. Leave the page open until the progress bar finishes.
- FileZilla or another FTP program: better for files over a few hundred MB, because it can resume a broken transfer. Connect with FTPS and drop the file into the top folder you land in.
- scp from your computer:
scp shop.sql.gz username@example.com:~/
Upload the compressed version if you have one. It's usually 80-90% smaller and you can import it without unzipping first.
Step 2: Open a terminal and check the file
- In cPanel, go to Advanced > Terminal (the first time, click I understand and want to proceed). Or connect from your computer with
ssh username@example.com. - You start in your home directory. List the file to make sure it's all there:
The size shown should match the file on your computer.ls -lh shop.sql.gz - Peek at the first lines to see what's inside:
zcat shop.sql.gz | head -30 # for .sql.gz head -30 shop.sql # for plain .sql
Look for a line starting CREATE DATABASE or USE. If there is one, remove it before importing (see "Fixing the file before you import" below), or the import will try to use the old host's database name.
Step 3: Import the file
Replace the example names with your own full database username and database name.
Plain .sql file
mysql -u username_shopuser -p username_shop < shop.sql
Compressed .sql.gz file
gunzip < shop.sql.gz | mysql -u username_shopuser -p username_shop
.zip file
unzip -p shop.zip | mysql -u username_shopuser -p username_shop
After you press Enter you'll see Enter password:. Type or paste the database user's password (nothing appears as you type -- that's normal) and press Enter.
Now wait. While the import runs, the cursor just sits there. When it finishes, you get your prompt back with no message at all. No news is good news: mysql only prints something if there's an error.
Check it worked
mysql -u username_shopuser -p username_shop -e "SHOW TABLES;"
You should see your table names. You can also open the database in Databases > phpMyAdmin and compare the table count with the original.
WordPress: the WP-CLI shortcut
If WordPress is already installed and its wp-config.php points at the right database, WP-CLI can import for you without typing the database details:
cd ~/public_html
wp db export ~/before-import.sql # safety copy of what's there now
wp db import ~/shop.sql
wp db import needs an uncompressed file, so run gunzip shop.sql.gz first. It reads the database name, user and password from wp-config.php.
Very big imports: keep them running if you disconnect
An import of several gigabytes can take a while. If your Terminal tab closes or your SSH connection drops, the import may stop with it. To avoid that, put the password in a temporary file and run the import in the background:
- Create the file (replace the values with yours):
cat > ~/.import.cnf <<'EOF' [client] user=username_shopuser password=YourDatabasePassword EOF chmod 600 ~/.import.cnf - Start the import in the background and log its output:
nohup sh -c 'gunzip < ~/shop.sql.gz | mysql --defaults-extra-file=$HOME/.import.cnf username_shop' > ~/import.log 2>&1 & - You can now close the window. Later, check whether it's still running and whether anything went wrong:
An emptypgrep -a mysql cat ~/import.logimport.logand no runningmysqlprocess means it finished cleanly. - Delete the password file and the dump when you're done:
rm ~/.import.cnf ~/shop.sql.gz
Fixing the file before you import
Most failed imports come from a few lines written by the old server. You can fix them with sed without opening a huge file in an editor. Work on an uncompressed copy (gunzip shop.sql.gz) and make a backup first (cp shop.sql shop.orig.sql).
| Problem | Fix |
|---|---|
CREATE DATABASE / USE lines | sed -i '/^CREATE DATABASE/d; /^USE `/d' shop.sql |
| MySQL 8 collation not recognized | sed -i 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' shop.sql |
DEFINER= clauses from the old server | sed -i 's/DEFINER=`[^`]*`@`[^`]*`//g' shop.sql |
Troubleshooting
ERROR 1045 (28000): Access denied for user 'username_shopuser'@'localhost' (using password: YES)
The username or password is wrong. Check the full username including the username_ prefix. If you're not sure of the password, set a new one in Databases > Manage My Databases > Current Users > Change Password (and update your site's config file to match).
ERROR 1044 (42000): Access denied for user ... to database 'olddb'
The file contains a USE or CREATE DATABASE line for the old database name. Remove it with the sed command above. If the database name in the error is your new one, the user hasn't been added to the database -- do that in Manage My Databases > Add User To Database with ALL PRIVILEGES.
ERROR 1050 (42S01): Table 'wp_posts' already exists
The database already has tables, often from an earlier attempt. Either import into a new, empty database or drop the existing tables first in phpMyAdmin (Structure > Check all > Drop).
ERROR 1273 (HY000): Unknown collation: 'utf8mb4_0900_ai_ci'
The dump came from MySQL 8. Our servers run MariaDB 10.11. Use the collation sed fix above, drop any tables that were created, and import again.
ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s)
The file has DEFINER clauses. Remove them with the sed command above.
ERROR 2006 (HY000): MySQL server has gone away
Usually a single huge statement (for example a table with very large rows) is bigger than the server allows in one go. Re-export from the old host with smaller inserts -- in phpMyAdmin's custom export, lower Maximal length of created query, or with mysqldump add --skip-extended-insert -- and try again. If it keeps happening, open a ticket and tell us which table it stopped on.
gzip: stdin: unexpected end of file
The upload didn't finish, so the compressed file is cut off. Upload it again (FileZilla is more reliable for big files) and compare the size with the original.
The import stopped with no error
If your connection dropped, the import may have stopped part way. Drop the partly imported tables and run it again using the background method above.
Common questions
Can I import a database bigger than my disk space?
No. The imported database counts toward your account's disk space. If you're close to your limit, delete the dump file after importing, or upgrade your plan.
Can I use my cPanel username and password instead of a database user?
Use a database user that's been added to the database. It keeps your cPanel password out of your shell history and config files.
Will you import it for me?
Yes. Upload the file to your home directory (not public_html), then open a ticket with the file name and the database you want it imported into.
Related guides
- How to Import and Export a Database with phpMyAdmin
- How to Use SSH, SSH Keys and Terminal in cPanel
- How to Create a MySQL Database and User in cPanel
- How to Connect to Your Website with FileZilla (FTPS)
- How to Change a MySQL Database User's Password
Still stuck? Open a support ticket and the Instant Access Internet Services team will help.
