# Search and replace in the database

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

Source: https://docs.wpwaterfall.com/tools-search-replace

Search and replace changes a string everywhere it appears in the database, for example an old hostname after a move. Every run starts as a dry run that changes nothing.

Needs WordPress on the environment. See [Run a site without WordPress](https://docs.wpwaterfall.com/run-a-site-without-wordpress).

## How do I run a search and replace?

1. Open the site, pick the environment in the top bar, and choose **Tools**, then **Search and replace**.
2. Enter **Search for** and **Replace with**. Turn on **Match case** or **Use a regular expression** if you need them.
3. Click **Run dry run**. WP Waterfall lists each table with its replacement count.
4. Read the counts. A table with far more matches than you expect means the search text is too short.
5. Click **Apply replacements** and type the site name to confirm.

If you change a field after the dry run, run the dry run again. **Apply replacements** unlocks only after a dry run that found matches.

The replace runs as a job. You can turn on **Clear the cache when done**.

## How do I undo a replace?

WP Waterfall takes a system snapshot before it applies anything and keeps it 48 hours. Restore it from [Backups](https://docs.wpwaterfall.com/backups). For a change that matters, take a manual snapshot first; [Backups](https://docs.wpwaterfall.com/backups) says how long each kind is kept.

## What does it cover on a Multisite network?

On a [WordPress Multisite](https://docs.wpwaterfall.com/wordpress-multisite) network, the replace covers the whole network: the main tables, `wp_blogs`, `wp_site`, `wp_sitemeta`, and the tables of every site. The counts list each table. If you replace the network address itself, WP Waterfall updates the network settings in `wp-config.php` to match, so WP-CLI still loads the network.

## Quick answers

**I clicked the run button and nothing changed.**
That was the dry run. Check the counts, then apply.

**Can I limit it to some tables?**
Yes, through the API with `tables`.

## API and MCP

- `POST /v1/environments/{id}/tools/search-replace` takes `search`, `replace`, `dry_run`, `confirm`, `case_sensitive`, `regex`, and `tables`.
- `dry_run` defaults to `true` and returns per-table counts in the job result. A real run needs `dry_run: false` and `confirm: true`.
- MCP tool: `search_replace`. It is a dry run until you confirm in the chat.

## Related

- [Database access](https://docs.wpwaterfall.com/database-access)
- [Backups](https://docs.wpwaterfall.com/backups)
- [Domains](https://docs.wpwaterfall.com/domains)
