Skip to content

Search and replace in the database

Replace a string across your database, see per-table counts in a dry run first, and apply the change with a snapshot behind you.

Search and replace changes a string everywhere it appears in the database, for example an old hostname after a move. Open the site, then Tools, then Search and replace.

Open it

  1. Open a site and pick the environment in the top bar.
  2. Choose Tools, then Search and replace.

Run a dry run

  1. Enter the text to search for and the text to replace it with.
  2. Run.

Every run starts as a dry run. Avaloi lists each table with its replacement count and changes nothing. Read the counts: a table with far more matches than you expect is a sign the search text is too short.

Apply the change

  1. If you changed a field after the dry run, run the dry run again so the counts match what you are about to apply.
  2. Press Apply.
  3. Type the site name to confirm.

The replace runs as a job. Avaloi takes a system snapshot first and keeps it 48 hours, so you can restore from Backups if the result is wrong.

Back up first when the change matters. A manual snapshot is kept at least 14 days, longer than the system snapshot.

On a WordPress Multisite network, the replace covers the whole network: the main tables, wp_blogs, wp_site, wp_sitemeta, and the tables of every site (wp_2_posts, wp_3_options, and so on). The counts list each table. If you replace the network address itself, Avaloi moves the network settings in wp-config.php to match, so WP-CLI still loads the network.

Quick answers

I pressed Run and nothing changed. That was the dry run. Check the counts, then press Apply and confirm.

Why do I have to run the dry run again? The counts belong to the fields you ran them with. A changed field needs a new dry run so you apply what you saw.

How do I undo a replace? Restore the snapshot Avaloi took before the run from the Backups tab.

API

  • POST /v1/environments/{id}/tools/search-replace

dry_run defaults to true and returns per-table counts in the job result. A real run needs dry_run: false and confirm: true.

Still stuck?

Email [email protected] with your site name and what you tried, or send us a message.