Skip to content
GPLWP Guides

How to migrate a WordPress site database between environments

Backup & Migration Time About 30–60 minutes 6 steps Updated 18 Nov 2026

BACKUP & MIGRATION
The short answer

You can migrate a WordPress database manually by exporting and importing SQL, updating the target configuration, and safely replacing the old URL. Use WP-CLI or a migration tool for serialized data; a plain text SQL replacement can corrupt settings, widgets and page-builder content.

The route
  1. 01Back up both environments
  2. 02Prepare the target database
  3. 03Export and import the database
  4. 04Replace the environment URLs
  5. 05Match the site files
  6. 06Test before switching traffic

What you need

  • Database and file backups of the source site
  • Database access through phpMyAdmin or WP-CLI
  • Administrator or hosting access to the target environment
  • The target site's database credentials and URL

Back up both environments

Take a fresh backup of the source database and keep it outside the server. Also back up the source files, especially wp-content and wp-config.php. A database backup contains posts, pages, users, comments and settings, but not themes, plugins, uploads or configuration files.

Put the source site into maintenance mode or pause writes if possible. This matters for WooCommerce and busy sites: orders, form submissions or comments created while you are exporting may not exist in the copy you import.

Prepare the target database

Create the target MySQL or MariaDB database and database user, then record the database name, username, password and host. If the target uses different credentials, update the target wp-config.php rather than trying to make the old configuration work unchanged. WordPress reads its database connection details from this file.

Use an empty target database for a complete replacement, or make a separate backup first if the target contains data you may need. Do not import a full source dump over valuable target data without deciding which environment is authoritative.

Export and import the database

With phpMyAdmin, select the source WordPress database, choose Export, use the SQL format, and download the export. Select the target database, choose Import, and upload the SQL file. The target database should normally have no existing WordPress tables for a full replacement.

If you have shell access, WP-CLI is usually more reliable for large databases: wp db export source.sql on the source, followed by wp db import source.sql on the target. These commands use the credentials in wp-config.php.

Replace the environment URLs

If the domain, protocol or installation path changed, update every relevant occurrence of the old URL. At minimum, check the home and siteurl values in the target site's options table. Do not replace URLs by editing the SQL file in a text editor: WordPress and plugins store PHP serialized data whose character counts can become invalid after a plain text replacement.

WP-CLI handles serialized values: run wp search-replace 'https://old.example' 'https://new.example' --dry-run first, review the report, then run the same command without --dry-run. On multisite, use the network option and review network tables separately. If you use phpMyAdmin, change only the basic URL fields manually and use a serialization-aware migration tool for the rest.

Match the site files

A database migration alone does not move the files that the database refers to. Copy the matching themes, plugins and uploads from the source, usually by copying wp-content, and make sure the target WordPress version and active code are compatible. If you only move the database, the site may show missing styles, missing images or fatal errors from absent plugins.

Check wp-config.php for the target database details and any environment-specific constants. If you temporarily added WP_HOME, WP_SITEURL or a relocation setting to regain access, remove or correct it after the database values are fixed; leaving relocation controls active can create a security problem.

Test before switching traffic

Open the target homepage, log in, test several posts, forms, menus, media files and plugin screens, then check the browser console and server error log. Visit Settings → Permalinks and save the existing structure to refresh rewrite rules if links return 404 errors. Clear page, object and CDN caches.

If WordPress shows the installation screen, check that wp-config.php points to the imported database, the table prefix matches, and the home and siteurl rows exist. If layouts or widgets break, restore the backup and repeat the URL replacement with a serialization-aware method rather than more SQL replacements.

Fast way: for regular staging-to-live or local-to-staging work, use WP Migrate DB Pro. It provides push-and-pull migrations, URL replacement that accounts for serialized data, backups and migration logs, so you can avoid repeating the export, import and search-replace work manually.

The fast route

Let WP Migrate DB Pro do it

Push-and-pull database migrations with serialized-data handling and URL replacement; ideal for developer workflows between staging and live sites.

Get WP Migrate DB Pro

Sources

  1. developer.wordpress.org /advanced-administration/security/backup/database/?utm_sourc…
  2. developer.wordpress.org /advanced-administration/upgrade/migrating/?utm_source=opena…
  3. developer.wordpress.org /cli/commands/db/dump/?utm_source=openai
  4. developer.wordpress.org /cli/commands/search-replace/?utm_source=openai
  5. reddit.com /r/Wordpress/comments/1vto625/install_page_appears_after_db_…

Questions

Can I migrate only the WordPress database?
Yes, but a database-only migration is rarely a complete site migration. The database contains content and settings, while themes, plugins, uploads and configuration remain in the filesystem. Copy the matching <code>wp-content</code> files and check <code>wp-config.php</code> as well, or the imported database may refer to files that do not exist on the target.
Why should I avoid find-and-replace in an SQL file?
Avoid plain text replacement because WordPress and plugins can store URLs inside PHP serialized values. Changing the string without updating its recorded length can corrupt widgets, theme settings, custom fields and page-builder data. Use WP-CLI <code>search-replace</code> or a migration tool that explicitly handles serialized data.
Do I need to change both home and siteurl?
Usually, yes, when the target environment has a different URL or installation path. The <code>siteurl</code> value identifies where WordPress core is installed, while <code>home</code> is the public site address. Confirm the correct table prefix before editing the options table, because it may not be <code>wp_</code>.
What causes the WordPress installation screen after migration?
The installation screen usually means WordPress is reading the wrong or incomplete database. Check the database name, user, password and host in <code>wp-config.php</code>, then confirm that the imported tables use the expected prefix and that the options table contains <code>home</code> and <code>siteurl</code>. Restore the backup if the import was incomplete.
Is a migration plugin necessary for this job?
No. Manual export and import works well for a small, stable site when you have database access and can use WP-CLI. A migration plugin becomes useful for repeated staging and live transfers, large databases, multisite work or any migration where serialized URL replacement and rollback records need to be handled consistently.