Black Friday hosting deals · every offer with its renewal price

// wordpress & cpanel how-tos

How to move a WordPress database to a new server or web host

Your WordPress database is where every post, page, comment and setting lives. Without it, WordPress is just software that can't work. Moving it to a new host takes about five minutes once you know where to click.

1. Download the database from cPanel

This is the easiest way to move a MySQL database. Log in to your old host's cPanel and open Backup in the Files section.

Skip the full backup at the top of the page. Under Download a MySQL Database Backup, you'll see your databases; if you run one site, there's just one. Click its name and the file downloads to your computer as a compressed .sql.gz file. Remember where you save it.

Not sure which database your site uses? Open wp-config.php in File Manager and look at the DB_NAME line.

2. Restore it on the new host

There are two ways to restore the database on the new server.

From cPanel Backup. This works when you moved your whole blog and the new database has the same name and user as before. Log in to the new cPanel, open Backup, and under Restore a MySQL Database Backup, choose your file and click Upload. A page full of messages means the restore worked.

From phpMyAdmin. This works for both new and old installs, because it replaces the tables inside an existing database. In the new cPanel, open phpMyAdmin from the Databases section, click your database name on the left, then the Import tab. Choose your file, scroll down and click Import (or Go on older versions). Large databases take a few minutes.

If the new install already has tables with the same prefix, drop them first (select all tables, then Drop), or the import stops on duplicates.

3. Or export it with phpMyAdmin

If the cPanel backup option fails, export from phpMyAdmin instead. Log in to the old cPanel, open phpMyAdmin, select your database and click Export. The Quick method with SQL format is fine for most sites. Save the file, then import it on the new host as described above.

phpMyAdmin imports plain .sql files as well as gzip, bzip2 or zip archives. Hosts limit the upload size, though, and the limit appears on the Import page. If your file is bigger, compress it, or ask your host to import it for you; most do it for free.

4. Connect WordPress to the database

Your database usually has a different name, user or password on the new host. Open wp-config.php on the new server and update DB_NAME, DB_USER and DB_PASSWORD to match the database you created there. DB_HOST is usually localhost, but some hosts use a different server name.

If you also changed your domain, the old address is saved inside the database. Use a search-and-replace tool such as WP-CLI's search-replace command or a plugin like Better Search Replace, never a plain text find-and-replace, which breaks serialized data.

That's it: your database is on the new server, and you can log in to your blog. If pages show a redirect error afterwards, see how to fix a WordPress redirect loop.

FAQ

How do I export a WordPress database from cPanel?

Open Backup in cPanel and click your database name under Download a MySQL Database Backup. You can also open phpMyAdmin, select the database and use the Export tab.

How do I import a WordPress database on a new host?

Create a database and user on the new host, open phpMyAdmin, select the database, then use the Import tab to upload your .sql or .sql.gz file. Finally, update DB_NAME, DB_USER and DB_PASSWORD in wp-config.php.

What if my database is too big for phpMyAdmin?

Compress it as .gz or .zip, which phpMyAdmin accepts, or ask your host to import it for you. Many hosts also offer free migrations that move the database and files together.

Keep reading

WRITTEN BY

Fathi Arfaoui

Fathi Arfaoui has helped people choose web hosting, start blogs and build WordPress sites since 2013. He founded SiteHostingFinder to replace opinion-based hosting reviews with real prices and public data. He has been a HostGator customer since 2013 and has hosted 40-50 WordPress sites on Pressable since 2017.