How to find and replace in the WordPress database

Updating your database records can take a long time if you do it manually. Fortunately, there is a way to update WordPress database records in bulk. In this article, we will cover the tutorial on how to perform a WordPress database search and replace with a WordPress plugin and a MySQL query.

Reasons to use the find and replace function in a WordPress database

Many times, you may find yourself needing to search and replace words or strings on your WordPress website for any of the following reasons:

  • You want to modify a keyword. In this scenario, you chose a keyword, for example, the keyword to, a few months ago because you thought it was good for the SEO of your website. However, now, after a few months, you realize that another keyword, for example, the keyword B, it is more viable for your WordPress site. Now, if this keyword is scattered all over your website, a manual way to replace it involves opening a 100MB database file, modifying it, and then uploading it again. (Don’t worry, we promise there are better ways to do this, and we’ll get to those in a bit.)
  • You noticed that you repeatedly made a grammatical (or spelling) or typo error on your website and now you want to find and replace its occurrences throughout your website.
  • After a WordPress update, some strange characters have started showing up on your website and you want to get rid of them.
  • You added a URL or a set of phrases to some of your posts, but you have no idea specifically which posts they were. For example, you’ve added an author bio to the bottom of some of your articles and want to update it.
See also  How deals with DDoS attacks

So we have mentioned some scenarios where you may need the “find and replace” function, but it is okay if your scenario is a bit different from those mentioned. No matter what the scenario is, going through each file and searching manually is a tedious job that no one wants to do. However, luckily for us, there are ways to quickly and efficiently find and replace things on your WordPress website. One big downside though is that if you make a mistake while searching and replacing, you won’t be able to undo your changes. So consider before proceeding to avoid any serious data loss.

Option 1: Use a plugin

Plugins make the life of WordPress website owners easier every day. If you don’t have any experience as a developer or just don’t want to go through the pain of running SQL queries, then you can simply use plugins like or to search and replace in the WordPress database. The first thing you need to do is install the plugin. You can enter the WordPress administration panel and then go to plugins -> Add new.

In the search field, type Better Search Replace and install it.

click on Activate when the installation is complete and the plugin will be deployed. You can find it through Tools-> Better Search Replace.

Then, you will have to enter the information you want to change:

  • the section of Search must contain the phrase or string you want to change.
  • Replace with should contain the value you want to put in place of the previously used one.
  • select tables allows you to choose which tables in your database will be affected. If you want to select them all, you can use CTRL+A. Or, you can select individual tables by holding down CTRL and clicking on them.
  • If you want the action Do not consider upper case and lower casemake sure to check the box.
  • check the box Do you want to run a drill? if you want to review the changes first before applying them.
See also  The 13 Best Image Formats and When to Use Them

If you run the plugin without the option to run a mock, it will immediately make changes to your database and you will see output like this:

Congratulations! You have successfully edited all your WordPress database entries using a plugin.

Option 2: Use a MySQL query

It is also possible to perform a search and replace operation using phpMyAdminwhich is usually located in the hosting control panel.

In case you have many databases in your account, you can open the file wp-config.php to find the name of the database your website uses.

When you log in to phpMyadmin, select the database that WordPress uses and click the tab SQL.

This is the syntax of the query you will use to perform the operation:

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘Text to search’, ‘text to replace it with’);

For example, if you wanted to update the posts table, you could do so using this query:

update wp_posts set post_content = replace(post_content, ‘Find this text’ , ‘Replace it with this’);

Note: wp_ should be replaced with the proper prefix used by your WordPress database tables.

When you have finished writing the query, click the “Go” button.

After a few moments of processing, you’ll see exactly how many rows were affected.

Excellent work! You have learned how to manipulate data from your WordPress database using SQL queries in phpMyadmin.

conclusion

Most things in WordPress are pretty easy to do, and search and replace is no exception. If you know SQL well and don’t want to install a plugin to help you get the job done, then the second option is the one for you. However, if you don’t want to get your hands dirty and just want a plugin to do the search and replace work in the WordPress database for you, then option one is the way to go.

See also  What is jQuery? Introduction to the jQuery library for beginners

Gustavo is passionate about creating websites. He focuses on the application of SEO strategies at for Spain and Latin America, as well as the creation of high-level content. When he is not applying new WordPress tricks you can find him playing the guitar, traveling or taking an online course.

Loading Facebook Comments ...
Loading Disqus Comments ...