Subscribe to
NSLog(); Header Image

Find and Replace in MySQL

This has come in handy the past few days. If only I could do it with regular expressions… and if only I knew regular expressions! 🙂

update [table_name] set [field_name] = replace([field_name], '[string_to_find]', '[string_to_replace]');

Works like a charm… though I'm not entirely sure how to replace line breaks. Some of my MT entries have four line breaks where they should have two.

2 Responses to "Find and Replace in MySQL"

  1. There is also a plugin to do SQL search and replace from within WordPress.

  2. You do have POSIX Regexp support in MySQL, but as far as I know you can only do matching and not replacing with it..

Trackback URI | Comments RSS

Leave a Reply

Please abide by the comment policy. Valid HTML includes: <blockquote><p>, <em>, <strong>, <ul>, <ol>, and <a href>. Please use the "Quote Me" functionality to quote comments.