Find and replace a string with MySQL query (or, how to automate base_url change)

Submitted by deeperdata - 3 years ago

The equivalent of a "Find and Replace" in your text editor or IDE... just for databases. In this example, I'm going to be replacing: The slow brown fox With: The quick brown fox I also find this very helpful when having to batch update the core_config_data.

// generic example
UPDATE your_table
SET your_field = REPLACE(your_field, 'The slow brown fox', 'The quick brown fox')
WHERE your_field LIKE '%The slow brown fox%';

// base_url example
UPDATE core_config_data
SET value = REPLACE(value, '', 'localhost')
WHERE value LIKE '%';
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean