WordPress

Database Search & Replace

Safely replace URLs, text, and serialized data across your WordPress database.

4 min read

Database Search & Replace

WordPress stores serialized PHP data in the database, which means a simple SQL REPLACE query breaks your data. GHP Cloud's search-and-replace tool uses WP-CLI under the hood to correctly handle serialized data during replacements.

When to use search and replace

The most common reasons to run a search-and-replace on a WordPress database:

  • Migrating to a new domain — replace all instances of http://old-domain.com with https://new-domain.com
  • Moving from HTTP to HTTPS — replace http://example.com with https://example.com
  • Restoring from staging — replace the staging URL with the production URL
  • Changing site URL after a move — update siteurl and home options

Running a search and replace

1. Open your site and click WordPress → Search & Replace

2. Enter the Search string (e.g., http://staging.example.com)

3. Enter the Replace string (e.g., https://example.com)

4. Choose tables to search (default: all tables)

5. Click Dry Run first to preview what will change

6. Review the dry run output, then click Run

GHP Cloud executes:

bash
wp search-replace 'http://old-domain.com' 'https://new-domain.com' --all-tables --report-changed-only

Understanding the dry run output

The dry run shows each table, the number of rows that would be changed, and a sample of the changes. Review this carefully before running the replacement — pay particular attention to unexpected matches in tables like wp_options or wp_posts.

Serialized data

WordPress serializes arrays and objects before storing them in the database. A serialized string looks like:

a:2:{s:3:"url";s:22:"http://old-domain.com/";s:5:"title";s:8:"My Site";}

WP-CLI's search-and-replace correctly updates the string length metadata when it replaces values inside serialized data. The GHP Cloud tool uses wp search-replace exclusively — never raw SQL — to ensure serialized data integrity.

After search and replace

After a URL change, flush all caches:

bash
wp cache flush
wp rewrite flush

GHP Cloud runs these commands automatically after a successful search-and-replace operation.

Was this article helpful?

Need help? →