May
14th

WordPress: MySQL Search and Replace using PHPMyAdmin

I made a slight modification to my page layouts today. I’ve read on John Chow’s blog and on Problogger’s blog that positioning your advertisement within the body of a post can result in a dramatic increase in revenue. Dean is working on his as well.

On Darren’s site, he writes that it’s simply a matter of the readers eye movement. When the banner is at the top of the page, the reader skips over it with no focus. However, when the advertisement is to the right of the content, the reader will actually skim over it.

You’ll notice that I still try to keep my home page clean – putting advertisements outside of the blog posts. I’m certain that changing that and making them more intrusive could make me more revenue; however, I’ve always fought that because it would really affect the readers I care about most – the ones that visit my home page daily.

One of the issues with putting this advertisement in the top right was that this is where I often place a graphic for aesthetic purposes and to dress up my feed and differentiate it from other feeds. I usually alternate a piece of clipart either right or left in the post using:

Image Left:
<img align=”left” src=”pic.jpg”>
Image Right:
<img align=”right” src=”pic.jpg”>

Note: Some folks like to utilize styles for this, but the alignment doesn’t work in your feed utilizing CSS.

Updating every post using Search and Replace:

To easily modify ever single image in every single post to ensure all my images are left justified can be done quite easily using an Update query in PHPMyAdmin for MySQL:

update table_name set table_field = replace(table_field, ‘replace_that’, ‘with_this’);

Specific to WordPress:
update `wp_posts` set `post_content` = replace(`post_content`, ‘replace_that’, ‘with_this’);

To correct my issue, I wrote the query to replace “image=’right’” with “image=’left’”.

NOTE: Be absolutely certain to backup your data prior to making this update!!!

  • steve
    This worked for me

    UPDATE wp_posts SET post_content = REPLACE( post_content, 'www.alznews.net', 'www.alzdigest.com' ) ;

    possibly the 'replace' needed to be capitalized
  • Abe
    this seemed to work better for my mysql.....

    UPDATE wp_posts SET post_content = replace( post_content, 'replace this', 'with that' ) ;
  • Hey Doug. Just used your instructions to update my email address in my WP DB. Worked like a charm. Thanks.

    BTW, came across this post in Google, searching "using mysql search replace query." Came up 3rd.
  • Woohoo! 3rd is good! My site seems to really have gotten some great placement in the Search Engines over the last year. Ironically, I rank above many Search Engine Blogs. :)
  • anjali
    have a problem to update secondds with "right" join in mysql
    UPDATE ivr_data SET RIGHT( TIME, 2 ) = '00' WHERE RIGHT( TIME, 2 ) != '00';
blog comments powered by Disqus