Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MySQL Database Find and Replace
###
# @source http://stackoverflow.com/a/19374770/400568
###
SELECT t,
INSERT(col,
LOCATE(@start, col),
LOCATE(@end, col) + CHAR_LENGTH(@end) - LOCATE(@start, col),
'') with_delimiters_replaced,
INSERT(col,
LOCATE(@start, col) + CHAR_LENGTH(@start),
LOCATE(@end, col) - LOCATE(@start, col) - CHAR_LENGTH(@start),
'') without_delimiters_replaced
FROM wp_posts.col, (SELECT @start := 'CHANGE:START', @end := 'CHANGE:END') init;
UPDATE t, (SELECT @start := 'CHANGE:START', @end := 'CHANGE:END') init
SET col = INSERT(col,
LOCATE(@start, col),
LOCATE(@end, col) + CHAR_LENGTH(@end) - LOCATE(@start, col),
'');
UPDATE wp_posts, (SELECT @start := 'CHANGE:START', @end := 'CHANGE:END') init
SET col = INSERT(col,
LOCATE(@start, col),
LOCATE(@end, col) + CHAR_LENGTH(@end) - LOCATE(@start, col),
'');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment