Search And Replace
Serialized-data-aware MySQL search & replace with dry-run preview, automatic backups and one-click restore.
Version 2.1.1 · Store extension, DEV access required · requires PHP 7.4+ with
mysqliandzlib, and a core with the shared style model, the task scheduler and the languages (I18n) Safely search and replace strings (including domains) in MySQL databases with serialized-data awareness, dry-run preview, automatic backups and restore.
Search And Replace rewrites text across a MySQL database without breaking serialized data, the classic WordPress migration problem. PHP-serialized values get their lengths counted again, JSON documents keep every byte but the replaced text, plain text is replaced directly. A value that cannot be rewritten safely is left as it is and listed. Every real run is preceded by a full mysqldump backup, restorable from the Backups tab.
Typical uses: domain migrations (old → new domain across wp_options, wp_postmeta, page builders…), HTTP → HTTPS, www normalization, and bulk literal-text replacements.
The extension speaks English and French: it follows the plugin's language (Options › Settings › General › Language, or your WHM language on Automatic). MySQL's own messages, and the server's logs, stay as they are written.
Run tab

Four numbered steps on one page.
1. Database
| Field | Default | Notes |
|---|---|---|
| Host | localhost |
Host name or IP. |
| Database name | — | Letters, digits, _, $, - only (max 64 characters, not starting with -). |
| User / Password | — | The database's MySQL credentials. |
Credentials are never stored: they stay in the page until you leave it and go to the server with each action. During a backup or a restore they sit for the length of it in a 0600 file of the extension's var/tmp (folder 0700), so the password is never on a command line. Nothing reads /root/.my.cnf: mysqldump and mysql run with their HOME on that folder, so root's own MySQL login can never stand in for the one you typed. The fields keep password managers from filling in WHM's root login.
Click Connect and list the tables: steps 3 and 4 appear.
2. What to replace
- Domain (recommended): the bare old domain and new domain (no
https://, nowww.). The six forms URLs take in a database (https://www.,http://www.,//www.,https://,http://,//) are replaced, the longest first. The list under Replaced is asked from the server, so it is exactly what the run applies.- HTTPS (on by default): every new URL in
https; off, anhttp://URL stayshttp://. - www: Keep as it is (default), Force www or Force no www. To change only the www of a site, enter the same domain twice.
- HTTPS (on by default): every new URL in
- Text, as typed: one literal search and replace (no pattern). Empty replacement removes the text.
In both modes the JSON-escaped form of the text (https:\/\/old.com) is replaced too.
3. Tables and columns
Everything is picked by default. A one-line summary says what is picked; Customize opens the checklist: each table (rows, size, engine) and its text columns (char, varchar, text, json), with Pick all, Pick none and Hide the tables. Never offered, never rewritten:
- the columns of a table's primary key (the run pages through the table by it) and generated columns;
- the tables without a primary key (listed, skipped, with a warning: a row the run cannot name is never updated);
- UTF-16 and UTF-32 columns (a search can never match them).
A column stored in another character set than UTF-8 (latin1…) shows its character set: it is read and written as its own bytes, so serialized lengths stay right in that character set, and it takes only the searches in plain ASCII (the results say which were not applied).
4. Run
- Dry-run: reads everything, changes nothing, shows what would change. Its progress shows as it goes.
- Run with backup: takes the backup, then applies the changes. A confirmation asks you to type the database name.
Only one operation (run, dry-run or restore) runs on the server at a time: a second one is refused at once. The progress shows above the sections, once a second; if the page loses its connection to the server, the operation goes on there and the page keeps showing its progress until it ends.
Results
A summary (rows changed, tables, duration, the backup's name), then:
- To know: the warnings (tables skipped, a note when picked tables are not InnoDB: the backup is a consistent snapshot for InnoDB only).
- Rows that could not be updated: rows whose UPDATE MySQL refused (a unique key, a character set…), left as they were. The run goes on; the count is exact, the list shows up to 500.
- Values left as they were: values holding the search that could not be rewritten without breaking them: a serialized value that does not read back (cut short, counted in another character set), one holding a PHP object, a JSON document this server cannot write back as it was. Change them from the site's own admin.
- The table of tables: rows read, changed, refused, and View to see the before and after of each change, centred on the change.
Backups tab
Each entry is the backup taken right before a run: database, when it was taken, when it will be deleted, size, the search and replace it was taken for, and:
- Download: the
.sql.gz. - Restore: a window with the database of the backup filled in, the credentials to type, and the target's name to type again. Restoring into another database says so. The credentials are checked first; a backup that does not read to its end is refused before anything is dropped. Restoring drops and creates again the tables in the backup, then puts their rows back: what was written to them since is lost. Its progress shows in the window.
- Delete: for good, after a confirmation.
Backups older than the retention (7 days by default, Settings tab) are deleted once a day at 03:17 by the core's scheduler, even while the extension is turned off, and when the Backups tab opens. The daily clean-up also deletes a backup left unfinished (.part) and a credentials file left behind by an interrupted operation. While an operation runs, the tab says so at the top of the list.
What's inside a backup
mysqldump --single-transaction --quick --no-tablespaces --routines --triggers --events --skip-lock-tables --hex-blob --set-charset --default-character-set=utf8mb4, gzip level 6, named <dbname>-YYYYMMDD-HHMMSS.sql.gz, 0600 in extensions/search-and-replace/var/backups/ (0700). Dump and restore each stop after an hour.
The run changes nothing on a bad backup. If mysqldump fails or times out, if the file cannot be written (full disk: every write is checked), or if the dump lacks its last line (-- Dump completed), the run stops before any UPDATE. A backup is written under a .part name and gets its real name only once complete, so a PHP that dies half way never leaves a file that looks valid.
Settings tab
| Setting | Default | |
|---|---|---|
| Keep backups for | 7 days | 1 to 365. Saved in config/settings.user.json, kept by updates. Restore puts the default back. |
The tab also says when the daily clean-up last ran (Daily clean-up).
How replacements stay safe
| Data shape | Handling |
|---|---|
PHP-serialized (s:14:"http://old.com";) |
Recognized by WordPress's strict rules, unserialized with allowed_classes => false (no object is ever created), strings rewritten, serialized again: every length counted afresh. A serialized string inside it is rewritten the same way. One that does not read back, or holds an object, is left as it is and listed. |
| JSON | Rewritten as text, raw and escaped forms, when a match can only fall inside a string: {}, big integers, spacing and escapes stay byte for byte. A document holding a serialized or JSON string, or a search that could match outside a string (1, true), goes through a decode and an encode, and only when this server writes it back as it was. |
| Plain text | Direct literal replacement, raw and JSON-escaped forms, in order. |
Other guardrails:
- Database, table and column names are checked against a strict whitelist and the live schema; what a tampered post names is dropped.
- Tables are read in pages of 500 rows by their primary key, one transaction per page: flat memory on tables of millions of rows.
- An UPDATE sets only the columns that changed: a
NULLbeside them staysNULL. - A refused UPDATE is counted and listed; a lost connection or a value larger than
max_allowed_packetstops the run with a clear sentence. - A real run stops if its backup disappears while it runs.
Turning it off, removing it
- Disable keeps the backups; the daily clean-up still deletes the expired ones.
- Remove (Options › Extensions) erases for good the settings, the history and every backup: download one first if you may need it. The databases are not touched. A run or a restore that is still going on keeps the extension from being removed until it ends.
- Uninstall WHM-Toolbox (over SSH) does the same for this extension.
Data & file map
| Path | Purpose |
|---|---|
extensions/search-and-replace/var/backups/ |
.sql.gz backups (0600, folder 0700) |
extensions/search-and-replace/var/tmp/ |
The credentials file of a dump or a restore while it runs (0600, folder 0700) |
extensions/search-and-replace/var/history.json |
Every backup, restore, run and dry-run, 500 entries at most |
extensions/search-and-replace/var/operation.lock, operation-status.json |
The lock of the operation that runs, and its progress (kept after a failure, for support) |
extensions/search-and-replace/config/settings.user.json |
The retention you set |
/var/log/toolbox-scheduler.log |
The daily clean-up (job search-and-replace:purge) |