Replacing old addresses in a WordPress database without breaking it

WordPress & CMS·· 33 views· 3 min read

The short answer: when you change the site’s address (a new domain, or from http to https), WordPress keeps the old address in thousands of places in the database: in page text, images, settings. Swapping them needs a tool that respects “serialized” data. A hand-made SQL REPLACE can break the site; use WP-CLI or a proper plugin, after a backup.

Why not by hand

Method Does it work?
Editing page by page Only for very small sites.
An SQL REPLACE (phpMyAdmin) No. Much data is stored with the length of the text written inside it (serialized). Swapping the text without fixing the length breaks the whole setting.
WP-CLI: wp search-replace Yes. It understands serialized data and lets you see what would change first.
A search-and-replace plugin Yes, if you have no SSH. Choose one that handles serialized data and has a “dry run”.

With WP-CLI (SSH), step by step

1 Take a backup of the database and the files: What to back up before you update.
2 Rehearse without saving, in the WordPress folder: wp search-replace "http://old.com" "https://new.com" --skip-columns=guid --dry-run. It shows, per table, how many swaps it would make.
3 If the numbers make sense, repeat the command without --dry-run.
4 Repeat for the variants of the address (with and without www, http and https), one at a time.
5 Clear the cache and open the site: LiteSpeed Cache. Look for broken images or the mixed content warning: Mixed content.
Leave the “guid” column as it is (hence --skip-columns=guid): GUIDs identify each post for feed readers and should not change. And do not run the swap without a backup: there is no “undo”. To change the site’s own address (not what is in the content), see Changing the WordPress site address.
The full case, from one domain to another, is in Moving WordPress to a new domain. If you do not have WP-CLI, see WP-CLI over SSH.

Prefer that we do it with you? Open a ticket with the two addresses (the old and the new).

Open a support ticket

SEE ALSO

Moving WordPress to a new domain without losing anything

Changing the WordPress site address, and what breaks when it goes wrong

Mixed content after moving to HTTPS: the padlock that will not turn on

WP-CLI over SSH: updating and fixing WordPress from the command line

RECOMMENDED PRODUCT

WordPress hosting

One-click install, updates handled, and speed that holds up. from $6.60/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.