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

Submitted by deeperdata - 4 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, '192.168.1.101', 'localhost')
WHERE value LIKE '%192.168.1.101%';
affiliate_link
Learn PHP
comments powered by Disqus
Proudly hosted on Digital Ocean