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

To search and replace text across a WordPress database, use WP-CLI’s wp search-replace command or a dashboard plugin such as Better Search Replace. Export a database backup first, preview the changes, and target only the tables and columns that need editing. These tools account for PHP serialized data, which a blind SQL replacement can damage.

Choose the right scope before replacing anything

A bulk replacement can affect more than visible page and post text. WordPress data may include post content, metadata, options, and plugin or theme values. Decide whether the change belongs across the database or only in particular tables or columns. For a typo in published content, a content-only change may be safer than a site-wide replacement.

For URL changes, write down the exact old and new strings, including the protocol (http or https), capitalization, trailing slash, and any path. A small difference can determine which records match.

Back up the database

Export the database before making changes, and confirm that you know how to restore it. WP-CLI provides wp db export; its command catalog lists database commands. The restore procedure depends on your host, so consult its documentation and keep the export somewhere appropriate.

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

Choose a replacement tool

Consideration WP-CLI Better Search Replace
Interface Terminal or command line WordPress dashboard plugin
Preview --dry-run reports proposed changes without saving Check the current plugin version’s documentation for available preview options
Scope Supports table selection, wildcards, column controls, and multisite options Plugin materials describe table selection; verify the options in the current version
Serialized data Official command reference says it intelligently handles PHP serialized data WordPress.org listing describes serialized-data support
Best suited to Users with shell access who want command-level controls Users who prefer an admin interface

WP-CLI

Use WP-CLI if you have shell access and are comfortable reviewing a database operation. Its search-replace command reference says: “Search/replace intelligently handles PHP serialized data, and does not change primary key values.” The command also supports dry runs, table and column selection, SQL export, and multisite scope controls.

By default, the command uses tables registered to $wpdb. In multisite, that means the current site’s tables unless you specify --network. The --all-tables option expands the operation to every database table, including tables outside the WordPress prefix, so use it only when that broader scope is intended. Custom plugin tables may also need deliberate consideration.

Better Search Replace

If you prefer the dashboard, Better Search Replace is listed in the WordPress.org plugin directory as a tool for replacing database text and URLs, with serialized-data support. Its changelog entry dated January 14, 2025 says PHP 8.1 or later is required. Because plugin requirements and maintenance can change, check the live listing for current compatibility and version details before installing.

Run a preview, then apply the replacement

With WP-CLI, first inspect occurrences and run a dry run. The database search command searches text columns and is case-insensitive by default. The examples below are templates, not commands tested on a particular site: substitute your exact strings and table names, and check the help for your installed WP-CLI version.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  1. Search for the old text:

    wp db search 'old.example' --all-tables-with-prefix

  2. Preview a replacement without saving changes:

    wp search-replace 'old.example' 'new.example' --dry-run

  3. For a narrower operation, name the tables and preview again:

    wp search-replace 'old phrase' 'new phrase' wp_posts wp_postmeta --dry-run

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  4. Review the report. If the proposed matches and scope are correct and your backup is usable, run the same replacement without --dry-run.

  5. Inspect affected pages and relevant site behavior after the replacement.

For a domain change, WP-CLI can also write transformed data to an SQL file instead of changing the live database:

wp search-replace 'old.example' 'new.example' --export=converted.sql

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

That option produces an export; it does not, by itself, apply the change to the live database. A domain-change example that excludes the guid column is:

wp search-replace 'http://example.test' 'https://example.com' --skip-columns=guid

Skipping guid is an example of an intentional column choice, not a universal rule. Decide whether it is appropriate for your specific replacement. The command reference documents additional controls such as --include-columns and --skip-columns.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why raw SQL replacement is risky

Some WordPress themes and widgets store values as PHP serialized data, which records string lengths. A URL replacement that changes a string’s length without updating that stored metadata can invalidate the value. WordPress’s migration handbook warns about this risk and recommends serialization-aware tools such as WP-CLI search-replace or suitable dashboard plugins.

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

For that reason, avoid a blind SQL REPLACE() across every table as your default workflow. A serialization-aware tool, a deliberate scope, and a recoverable backup reduce the risk of breaking stored data.

Finish the migration and verify the site

A database replacement may be only one part of moving a site to a new domain. Update the relevant site configuration as part of the migration, then check affected pages and features. If you used an exported SQL file, follow the appropriate import process for your environment before verifying the result.

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.