Skip to content
Tools

Search & Replace SQL

Change your site URL without corrupting serialized data

Runs in your browser. Nothing is uploaded.

The change

Read this before you run anything

WordPress stores many options as PHP-serialized strings, and a serialized string records its own byte length — s:19:"http://old-site.com". A plain SQL replace changes the text but not the length, so PHP can no longer unserialize the row. It does not error. The value just silently becomes empty.

What you lose: widget configuration, theme mods, and most plugin settings. Usually you do not notice until days later, and by then the backup you would have restored is gone too.

This is why the queries below deliberately do not touch wp_options.

What are you moving?
search-replace.sql

Take a database backup first. Not 'consider taking one' — take one. There is no undo for an UPDATE.

About the Search & Replace SQL

A naive SQL find-and-replace on a WordPress database breaks every serialized option it touches, because the stored string length no longer matches. This generates the queries that are safe, and explains exactly which ones are not.

FAQ

Questions

Can I change my WordPress site URL with a SQL find and replace?

Not safely, and this is the most-shared bad advice in WordPress. Many options are stored as PHP-serialized strings that record their own byte length. A plain SQL replace changes the text but not the length, so PHP silently fails to unserialize the row and the value simply disappears — taking widget settings, theme mods and plugin config with it.

What should I use instead?

WP-CLI: 'wp search-replace old new --all-tables --dry-run' first, then without --dry-run. It understands serialization and rewrites the length prefixes correctly. If you have no CLI access, the Better Search Replace plugin does the same thing from the admin.

Should I update the GUID column?

No. The GUID is a permanent unique identifier for a post, not a link, and feed readers key off it. Rewriting it makes every subscriber see every old post as brand new. WordPress documentation says explicitly not to change it.