howto: replacing a substring in a column value with a MySQL query

MySQL Reference Manual :: 13.2.10 UPDATE Syntax: “You sometimes run into the problem that you want to replace a substring occuring in a column with a different string, without touching the rest of the string. The solution is surprisingly simple, thanks to MySQL:

UPDATE xoops_bb_posts_text
SET post_text=(
REPLACE (post_text,
‘morphix.sourceforge.net’,
‘www.morphix.org’));

using the string function REPLACE, all items in the post_text column with ‘morphix.sourceforge.net’ get this substring replaced by ‘www.morphix.org’. Ideal when writing a script is just too much effort.”

This will be useful for changing a bunch of text on the various wiki pages for pixfestdoc.terrorware.com. I had a bunch of links that read ‘View/Upload Photos’ and I want to change them to ‘View/Upload Photos and Video’. This would have sucked to do through a web interface, but messing with the database should make it quick. I ran into a little problem with the Mediawiki handles caching so the changes didn’t show up right away, but I waited overnight and it worked out.

UPDATE: This the query that I used to add additional text to all the show pages:

update pixfestmw_cur set cur_text=(concat(‘== Photos/Video ==\n\n’, concat(cur_text, ‘\n\n== Audio ==\n\n== Stories ==\n\nTo read stories from this show, please click on the \’discussion\’ tab at the top of this page.\n\n== External Links ==’))) where cur_title like ‘%June_%’;