Knowledgebase

Search and Replace in a Database Print

  • databasesphpmyadmin, databases, database, plugins, woocommerce, wordpress, domain, https, migration, themes
  • 0

Changing values across many rows.

WHEN YOU NEED IT

After a domain change After moving from http to https After a migration where URLs changed

THE DANGER

Serialised data. Applications store some settings as text containing the length of each string.

A plain SQL replace changes the text without updating the recorded lengths, which corrupts the value silently.

Widget settings, theme options and plugin configuration are commonly stored this way.

THE SYMPTOM

Widgets disappearing, settings reverting, or a plugin behaving as though unconfigured, after a replace that appeared to work.

THE CORRECT TOOLS

A search-replace plugin that handles serialisation WP-CLI, which handles it correctly A dedicated search-replace script

Any of these. Not a plain SQL query.

THE PROCEDURE

  1. Back up the database.
  2. Run the replace with a tool that understands serialisation.
  3. Search afterwards for any remaining instances.
  4. Clear caches and test.

WHAT TO REPLACE

The full old URL including scheme, to the full new one.


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot