Performing Search And Replace In WordPress MySQL Database

I recently started hosting my blog images on my Amazon s3 bucket so I needed to update all image links in my blog articles to point to my Amazon s3 bucket.
Trying to update the images link one after the other wasn’t an option as I consider it time consuming and energy sapping. so what did I do? I had to do a MySQL database search and replace.

Below is the SQL query to do a mass search and replacement in your Database. All you need do is login to your site phpMyAdmin, go to your WordPress database, click the SQL tab and insert the sql code below.
SQL link Phpmyadmin

[sql]
UPDATE wp_posts SET post_content = REPLACE (
post_content,
‘Item to replace here’,
‘Replacement text here’);
[/sql]

Note: Change the prefix “wp” in “wp-post” to your DB prefix only if you have altered it.
Also you can run sql query in your WordPress dashboard using plugins like WP-manager

If the use of the SQL code above is too geeky for you, there are some good WordPress plugin to do the database search and replace job perfectly such as:

  • Search and Replace

    A simple plugin to search and replace strings / text in your WP database. You can search in ID, post-content, GUID, title, excerpt, meta-data, comments, comment-author, comment-email, comment-url, tags/categories and categories-description tables.

  • Safe Search Replace

    Shortcodes Quite a lot of plugins use shortcodes – deactivating them leaves your shortcodes unused and plain to your visitors. With this feature, you can remove existing shortcodes, rename them (in case of an update or plugin switch), and even remove, rename and add their attributes. This plugin searches your post titles, contents, excerpts and comments for words and replace them with something else. All operations, or tasks which you can do with this plugin can be undone safely anytime later.

  • Velvet Blues Update URLs

    If you move your WordPress website to a new domain name, you will find that internal links to pages and references to images are not updated. Instead, these links and references will point to your old domain name. This plugin fixes that problem by helping you change old urls and links in your website.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address