Search And Replace With phpMyAdmin

phpMyAdmin is the best, free and open source tool that is used to handle MySQL databases from the web browser itself. It is provided by all the major web hosting provides and can perform almost any task, ranging from creating, altering, deleting databases, columns, rows and tables. It can also execute SQL queries, can add/edit/delete users and can even be used to view data.

Why To Perform Search And Replace With phpMyAdmin

The most painful task in managing your database is when you have to replace one word, value, or any phrase with another, and this change has to be made in all the occurrences of that item. This can be done manually but it can take a lot of time, depending on the data in your database. But we have an easy solution. You can perform search and replace in phpMyAdmin which will take just one query and all of the replacement will be done by phpMyAdmin.

How To Perform Search And Replace With phpMyAdmin

  1. Open phpMyAdmin.
  2. From the left pane, select the database you want to perform search and replace on.
  3. Click on the “SQL” tab in the top navigation.
  4. Now in the text area paste the following code, replacing

    1. table_name” with the name of the table,
    2. column_name” with the name of the column,
    3. replace this item” with the item that needs to be replaced,
    4. replace with this item” with the item you want to replace it with.
    UPDATE table_name SET column_name = REPLACE ( column_name, 'replace this item', 'replace with this item');

  5. Now press the “Go” button and that’s all. You have successfully replaced all the occurrences of the undesired item with the desired one using phpMyAdmin.

NOTE If you make a mistake in typing or copying the query, it can make your database useless completely. Please take a complete backup of your database beforehand using the “Export” feature in phpMyAdmin itself, present in the top navigation menu.

Perform Search And Replace in phpMyAdmin on WordPress Database

Most of the people have asked me about changing all the occurrences of a particular item in WordPress post content. There are plugins that can do this quite easily but to do it using phpMyAdmin you have to take the same steps but the query can be made a little more specific.

The Query

UPDATE wp_posts SET post_content = REPLACE ( post_content, 'replace this item', 'replace with this item');

The query above is specifically for WordPress post content. Just follow the general process of search and replace in phpMyAdmin and change the query with this one.

REMEMBER Don’t forget to change the items.

Verdict
The phpMyAdmin search is quite powerful when performed carefully. It can solve huge problems and can save quite a lot of time. But exercise caution while performing search and replace, because this can render your database useless. For those bad times, always have a backup ready before executing any queries.
Play Safe…
Related Post