Get a free website with any plan

See how
WORDPRESS

Search and replace in the database (WP-CLI and a plugin)

Last updated

IN SHORT

Run a database search and replace in WordPress using the WP-CLI command wp search-replace over SSH, or use the Better Search Replace plugin in wp-admin. Both tools safely handle serialized PHP data so theme options and widgets do not break. Always back up your Flashcloud database before running any replacement.

The fastest way to do a search and replace in WordPress is wp search-replace 'old-value' 'new-value' via WP-CLI over SSH. It handles serialized data correctly, which is the one thing that breaks manual database edits. If you don't have shell access or don't want the command line, a plugin like Better Search Replace does the same job from wp-admin.

Either way, back up first. This operation touches your whole database at once, and there's no built-in undo.

Why you'd need this

Search and replace across the database comes up whenever a value is baked into content or settings and needs to change everywhere at once:

  • Moving a site from a staging URL to the live domain, or from http:// to https://
  • Changing a domain name entirely
  • Restoring a duplicated or migrated site whose database still points at the old location
  • Bulk-fixing a typo or outdated phone number, email, or company name across many posts

A plain find-in-database-editor approach fails here because WordPress stores some data as serialized PHP: arrays and objects flattened into a single text string with an exact character count baked in (s:8:"old text", where 8 is the byte length). Change the text without recalculating that count, and WordPress fails to unserialize the value at all. Widget settings, theme options, and some plugin data all use this format. Search and replace with a tool that understands serialization avoids the problem entirely; a manual SQL UPDATE or a plain-text find/replace in phpMyAdmin does not.

Before you run anything: back up

This is a whole-database operation, not a scoped edit. Take a fresh backup first, whichever layer you use:

  • Your Flashcloud hosting account has daily automatic backups. See backing up your WordPress site for how to restore from those if something goes wrong.
  • For a faster, more targeted rollback, export the database on demand right before you run the replace: wp db export before-search-replace.sql, or use phpMyAdmin's export tab.

If the change is risky or you're not sure what will break, do it on a staging copy first, confirm the site still works, then repeat the same command on live.

Option 1: WP-CLI (recommended)

If you have SSH access, WP-CLI is the right tool. Connect to your account over SSH, navigate to the WordPress install's directory, and run:

wp search-replace 'https://old-domain.com' 'https://new-domain.com'

A few flags worth knowing:

  • --dry-run: shows what would change without touching the database. Always run this first.
  • --skip-columns=guid: leaves the guid column alone, which is standard practice since guid is meant to be a permanent identifier, not a live URL.
  • --all-tables: also scans tables outside the standard WordPress prefix, useful if a plugin created its own tables.
  • --precise: uses PHP string functions instead of SQL REPLACE(), slower but more reliable on multibyte or unusual text.

A full dry-run-then-commit sequence for a domain change:

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

WP-CLI reports how many replacements it made per table, so you can sanity-check the count before moving on.

Option 2: a plugin, if you don't have SSH

Better Search Replace (free, in the WordPress plugin directory) gives you the same underlying operation through a form in wp-admin:

  1. Install and activate it from Plugins → Add New, search "Better Search Replace."
  2. Go to Tools → Better Search Replace.
  3. Enter the old and new values, select the tables to search (default is all of them), and check Run as dry run first.
  4. Review the reported changes, then uncheck dry run and run it for real.

It handles serialized data the same way WP-CLI does, which is the whole reason to use a dedicated tool instead of a raw SQL query.

After the replace

Clear any caching layer so you're not looking at stale pages. Flashcloud hosting runs on LiteSpeed, and WordPress installs come with the LiteSpeed Cache plugin, so purge the cache from there if it's active on the account. Then load a few pages, check images and links resolved to the new value, and if it's a store, walk through a test checkout. If something looks wrong and you took a fresh export, restore it and try again with a narrower search term.

If the site was running slowly before or after a domain move and you want to rule out other causes, see my WordPress site is slow.

When to contact support

If a search-replace goes wrong, mismatched serialized data, a site that won't load, a database that looks corrupted, don't keep experimenting on production. Open a ticket from the portal's Support section. It reaches a real person, and if you have a recent backup or export on hand, mention it so they can restore quickly while sorting out the rest.

Common questions

Why cannot I run a search and replace in phpMyAdmin?

Plain SQL edits break serialized PHP strings. WordPress stores settings and theme options with exact character counts, which raw database edits do not recalculate. Tools like WP-CLI and Better Search Replace update these counts automatically so values remain readable.

What should I do before running a search and replace?

Back up your database. Use wp db export before-search-replace.sql over SSH, export via phpMyAdmin, or rely on your daily Flashcloud backups. Search and replace modifies your entire database at once with no built-in undo.

How do I test changes without modifying the database?

Add the --dry-run flag to your WP-CLI command. If you use the Better Search Replace plugin, check the Run as dry run box in the form. Both options report which tables contain matches without writing changes to the database.

Why does my site still show old links after the replace?

Your site is likely serving cached pages. Purge the LiteSpeed Cache plugin in WordPress to force the server to show the updated database values.

CAN'T FIND IT?

Real humans answer fast.

Hosting with us? Open a ticket and a real person replies - no scripts, no upsells. Still choosing a host? The same team is included with every plan, from day one.