Moving a WordPress site to a new domain means updating dozens of URL references stored across your database. This guide walks you through every query you need β€” and the tool below generates them automatically based on your domains and table prefix.

Back up first. Always export your database before running any SQL. A single wrong UPDATE can break your site and may be impossible to reverse without a backup.

SQL query generator

Fill in your old domain, new domain, and table prefix, then click Generate.


          
        

Why you need to update the database

WordPress stores your site URL in two places: the wp_options table (as siteurl and home) and scattered throughout post content, post meta, and widget serialized data. Simply pointing your DNS to a new server is not enough β€” every internal URL reference must be updated too, otherwise images break, links 404, and your admin panel may redirect to the old domain.

Which tables are affected

Table What changes Why it matters
wp_options siteurl and home values Controls where WordPress thinks it lives
wp_posts URLs in post_content and guid Embedded images, links, iframes in content
wp_postmeta URLs stored in meta values Featured image paths, SEO plugin data, ACF fields
wp_usermeta Serialized user session data Stored capabilities and dashboard preferences

How to run the queries

  1. 1

    Open phpMyAdmin from your hosting control panel (cPanel, Plesk, etc.) or connect via a MySQL client like TablePlus or DBeaver.

  2. 2

    Select your WordPress database from the left sidebar. Make sure you are in the correct database β€” especially if your host has multiple WordPress installs.

  3. 3

    Click the SQL tab at the top, paste your generated queries, and click Go. All statements run in sequence.

  4. 4

    Clear all caches β€” your hosting cache, object cache (Redis / Memcached), and any caching plugin (WP Super Cache, W3 Total Cache, WP Rocket). Then visit your new domain and confirm everything loads correctly.

If you see a white screen or get stuck in a redirect loop after running the queries, temporarily add define('WP_SITEURL', 'https://newsite.com'); and define('WP_HOME', 'https://newsite.com'); to your wp-config.php to override the database values while you troubleshoot.

WordPress Multisite considerations

For a multisite network, the generated queries above handle the per-subsite tables (e.g. wp_2_options, wp_2_posts). Run the generator once per subsite, changing the prefix each time. You also need to manually update three network-level tables that cannot be handled with a simple REPLACE():

  • wp_blogs β€” the domain column for each subsite
  • wp_site β€” the domain column for the network root
  • wp_sitemeta β€” the siteurl option value

Edit those rows directly in phpMyAdmin using the table view rather than SQL queries, as their structure varies by network configuration.


Frequently asked questions

Does this handle serialized data?

No β€” SQL REPLACE() breaks PHP serialized strings because the byte-length prefix becomes incorrect after substitution. For serialized data (common in themes and page builders like Elementor or Divi), use WP-CLI: wp search-replace 'oldsite.com' 'newsite.com' --all-tables. It is serialization-safe and is the most reliable method for complex sites.

Should I include https:// in the domain fields?

Yes, include the full protocol (https://oldsite.com) for the wp_options queries. The guid update in wp_posts also uses full URLs. Matching the exact string stored in the database avoids partial replacements that could corrupt other values.

What if my site is still on HTTP?

If you are also migrating from http:// to https:// at the same time as changing the domain, run the generator twice: once for the domain change keeping the same protocol, then again changing http:// to https:// for the new domain.

Do I need to update wp_users or wp_comments?

Rarely. The wp_users table stores email addresses, not URLs. The wp_comments table has an author_url column but it holds external commenter URLs β€” you generally do not need to update it during a domain migration.