October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk8 min

How to Change WordPress URLs in the MySQL Database Safely

A practical, serialization-safe guide to changing WordPress siteurl and home values, migrating old links with WP-CLI, and recovering from redirect or configuration errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To change a WordPress site’s address, update the siteurl and home rows in the site’s options table, then replace the old address in stored content. The safest complete workflow is to back up the database, inspect the current values, preview a WP-CLI search-and-replace with --dry-run, run it while skipping the guid column, and then verify the front end and administrator login.

Changing only the two options fixes WordPress’s primary addresses but leaves old domains in post content, metadata, widgets, theme settings and builder data. Conversely, a blind SQL replacement across every table can corrupt PHP-serialized values. The sections below show which method fits each situation and how to recover when the URL change causes redirects or a locked-out dashboard.

As an Amazon Associate I earn from qualifying purchases.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the WordPress URL settings control

WordPress stores two separate addresses in the options table:

  • siteurl: the address where the WordPress core installation is located.
  • home: the public address visitors use for the site.

They are normally in a table named wp_options. Your installation may use a different prefix, such as abc_options, because the table name is built from the prefix configured for that site. Do not assume that wp_options exists; confirm the actual prefix before running SQL.

For a conventional installation, both values might be https://old.example.com. In a less common setup, WordPress core can live at a different path or subdomain from the public site, so siteurl and home should not be changed to identical values unless that is the intended architecture.

These rows govern generated URLs and where WordPress expects its files and front end to be. They do not rewrite every occurrence of the old address elsewhere in the database. Links in posts and pages, attachment metadata, serialized widget settings, theme options, page-builder layouts and plugin records can still point to the old address after the two rows are changed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the method before touching the database

Method What it changes Serialized-data safety Access required Best use
WP-CLI option update plus search-replace The two URL options and, when run, matching values throughout registered WordPress tables WP-CLI accounts for PHP-serialized string lengths Shell access and WP-CLI Most migrations and domain changes
SQL update on the options table Only siteurl and home Safe for these plain URL rows, but it does not repair serialized content elsewhere A MySQL client or database panel Emergency access or a change limited to the primary addresses
Raw SQL replacement across tables Every matching text value selected by the SQL Risky; byte-length prefixes in serialized values are not recalculated A MySQL client Generally avoid
WP_HOME and WP_SITEURL constants Overrides the database values at runtime Does not rewrite stored content Access to wp-config.php Troubleshooting or temporarily pinning an address

Use one method deliberately rather than mixing partial changes. If you have WP-CLI, it provides the safest way to update URLs throughout WordPress because it understands serialized data. If you only need to make the site boot after a domain mistake, an options-table update can restore the two controlling values; plan a serialized-data-safe replacement afterward.

Prepare a safe URL change

1. Confirm the destination address

Write down the exact old and new values, including the scheme (http or https), capitalization and any path. A replacement from http://example.com to https://example.com is different from a replacement that also changes a path, such as https://example.com/blog to https://example.com. Do not include a trailing slash unless the stored value actually includes one; an inconsistent search string can miss links or create doubled slashes.

2. Back up before editing

Create and test a restorable database backup before running either SQL or WP-CLI. Keep the backup separate from the server being migrated. A URL replacement can affect thousands of rows, and an incorrect destination, table selection or prefix is easiest to undo by restoring the backup.

3. Record the current values

From the WordPress installation directory, WP-CLI can show the values that WordPress currently reads:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
wp option get siteurl
wp option get home

Save the output with the backup. If these commands report values different from the address you expected, stop and resolve that discrepancy first. It may indicate a different installation, a nonstandard table prefix or constants in wp-config.php.

4. Check for configuration constants

Open wp-config.php and look for definitions of WP_HOME and WP_SITEURL. When present, they override the corresponding database rows. Updating MySQL while those constants still point to the old address can make the change appear ineffective. Note the existing lines so they can be restored or removed intentionally after the migration.

Preferred workflow: WP-CLI with a dry run

Step 1: Preview the content replacement

Run this from the directory containing wp-config.php, substituting your real domains:

wp search-replace 'https://old.example.com' 'https://new.example.com' --skip-columns=guid --dry-run

The preview reports how many replacements would be made without saving them. Review the table and column counts. A result of zero usually means the old value is not present in the tables WP-CLI examined, the command is being run against the wrong installation, or the stored address differs in scheme, path or trailing slash.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The example skips the guid column, as shown in the WP-CLI migration guidance. The retrieved documentation does not establish the reason for that recommendation, so treat it as a documented migration option rather than an invitation to rewrite identifiers indiscriminately.

Step 2: Run the replacement

When the preview matches your plan, run the same command without --dry-run:

wp search-replace 'https://old.example.com' 'https://new.example.com' --skip-columns=guid

WP-CLI’s replacement logic updates serialized PHP values while preserving their recorded byte lengths. That matters for arrays used by widgets, themes, plugins and page builders; a text-only SQL substitution can leave those lengths wrong and make the values unreadable.

Step 3: Decide whether to use --all-tables

By default, WP-CLI targets tables registered to WordPress through $wpdb. If the old address also exists in custom tables that are not registered there, preview a run with --all-tables and inspect the scope carefully:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
wp search-replace 'https://old.example.com' 'https://new.example.com' --skip-columns=guid --all-tables --dry-run

Only run the live --all-tables command when you know those tables belong to this site and the replacement is appropriate for them. A shared database can contain unrelated applications or tables whose URLs should not change.

Step 4: Ensure the two options are correct

If the search-and-replace included the options table, it may already have changed home and siteurl. Check them:

wp option get siteurl
wp option get home

If they are still wrong, update them explicitly:

wp option update siteurl 'https://new.example.com'
wp option update home 'https://new.example.com'

Use different values when your architecture intentionally places WordPress core and the public site at different addresses.

Step 5: Flush caches and test

Flush WordPress and hosting or reverse-proxy caches according to your environment. Test an incognito front-end request, several internal links, an image, the administrator login and a representative post or page. Check that the browser remains on the new scheme and host and that no old-domain requests remain in page source or network activity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Changing only siteurl and home with SQL

An options-only change is useful when WP-CLI is unavailable or the immediate goal is to restore access. It does not perform a migration of content URLs.

Identify the correct table prefix

Read the $table_prefix setting in wp-config.php, or inspect the database for the table containing rows named siteurl and home. Replace wp_options below with the actual table name.

Run the targeted update

UPDATE wp_options
SET option_value = 'https://new.example.com'
WHERE option_name IN ('siteurl', 'home');

Run the statement only after confirming the selected table belongs to the intended site. Then query the rows to verify the result:

SELECT option_name, option_value
FROM wp_options
WHERE option_name IN ('siteurl', 'home');

This statement is deliberately narrow. It does not change URLs in posts, post metadata, comments, user metadata, plugin options or custom tables. Follow it with WP-CLI search-replace when a complete domain migration is required, or update the remaining data with a tool that understands serialization.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why a broad SQL replacement is dangerous

WordPress stores many options and metadata values as PHP-serialized strings. A serialized string records its byte length, so changing old.example.com to a longer or shorter value without recalculating that length can corrupt the value. Broken serialized data may reset widgets, disable theme settings, damage builder layouts or cause PHP warnings. A SQL REPLACE() over every table cannot reliably repair those lengths; use WP-CLI or another serialization-aware migration utility instead.

Using WP_HOME and WP_SITEURL for troubleshooting

Adding these constants to wp-config.php makes WordPress use the specified addresses regardless of the values in wp_options:

define( 'WP_HOME', 'https://new.example.com' );
define( 'WP_SITEURL', 'https://new.example.com' );

They can be useful when a bad database value prevents the dashboard from loading, or when you need to pin the expected address while diagnosing a redirect. They do not rewrite old links in stored content and do not change the database rows. Once the underlying values are corrected, remove or revise the constants if they are no longer part of the intended configuration; leaving conflicting definitions in place makes later database changes appear ineffective.

If the site redirects repeatedly, inspect wp-config.php for constants that disagree with the database and with the requested host or scheme. Check web-server or proxy redirects as well, because a database edit cannot override a redirect issued before WordPress runs.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

The RELOCATE constant: temporary recovery only

WordPress migration guidance describes a RELOCATE constant that can change the stored siteurl under specific recovery conditions. It is not a general replacement for a planned search-and-replace. If you use it, remove it immediately after the address is corrected: the migration guidance warns that leaving it defined can be insecure in some configurations. Do not leave recovery constants in production as a substitute for setting the correct database values and updating stored content.

Diagnose common failures after the change

The front end still uses the old address

  • Check whether WP_HOME or WP_SITEURL in wp-config.php overrides the database.
  • Run wp option get siteurl and wp option get home from the correct installation directory.
  • Flush page, object, CDN and reverse-proxy caches.
  • Confirm that the browser is reaching the intended server and not a second installation.

The site redirects in a loop

  • Compare the requested scheme and host with both option values and any configuration constants.
  • Look for conflicting HTTP-to-HTTPS or host redirects at the web server, proxy and application layers.
  • Temporarily correct the values with a targeted options update or matching constants, then remove conflicting overrides.

The dashboard will not accept the new login URL

  • Verify that both the public host and the WordPress core host are correct for the installation.
  • Clear browser cookies for the old and new hosts and test a private window.
  • Check that the replacement did not alter a path that is required by the server configuration.
  • Use the recorded backup and option values to restore the last known-good state if the installation cannot be reached.

Images or internal links still point to the old domain

The options-only SQL statement never addresses these references. Run a serialized-data-safe search-replace across the appropriate WordPress tables, preview first, and include custom tables only after confirming their ownership. Check post content, metadata, widgets, theme settings and builder data separately when a plugin stores URLs in a format or table outside the default set.

Widgets or layouts broke after an SQL migration

Restore the backup if possible. A broad raw SQL replacement may have left serialized byte lengths inconsistent. Repeating the same SQL replacement will not repair those lengths; use a serialization-aware tool on the original data and verify the affected options or metadata after restoration.

Post-migration verification checklist

  • siteurl and home return the intended values.
  • No unintended WP_HOME, WP_SITEURL or RELOCATE definitions remain in wp-config.php.
  • The home page, a post, a page, an image and a stylesheet load from the new address.
  • Administrator login, logout and password-reset links use the new host.
  • Internal links and media URLs no longer contain the old address where they should not.
  • Serialized widgets, theme settings and builder layouts still render correctly.
  • Cache layers have been flushed, and no old-host redirect or mixed-scheme behavior remains.
  • The backup is retained until the site has been monitored successfully.

Which approach should you use?

Choose WP-CLI when the change is a migration, because it combines explicit updates to the two controlling options with a serialization-safe replacement across WordPress tables. Choose the narrow SQL update only when you deliberately need to change those two rows and will handle content references separately. Avoid raw SQL find-and-replace across all tables unless you have a tool and a recovery plan that preserve serialized data. Use configuration constants as a temporary override or diagnostic aid, not as a replacement for correcting the stored values.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.