MySQL Search and Replace

If you would like to perform a Search and Replace in your MySQL Database without using plugins you can easily do that through phpMyAdmin, in this tutorial we will show how to perform that for WordPress Posts. The MySQL Search and Replace is particularly useful when changing the domain of your WordPress website.

Open your phpMyAdmin tool from your cPanel account

cPanel databases

Navigate to the Database of your WordPress installation and select the `wpDbPrefix_posts` table

phpMyAdmin Database

* Note: If you’re not certain what your Database is you can find out that through your wp-config.php file

Transfer your project to WebHostFace

You should be able to see that the Column that we’ll need to edit is called `guid`

guid column

Click on the “SQL” tab on the top of your phpMyAdmin interface

phpMyAdmin SQL tab

Managed WordPress Hosting with Personal WP Assistant

MySQL Search and Replace Query for WordPress

UPDATE `wpqw_posts` SET guid = REPLACE(guid, 'https://oldUrl.com/', 'https://newUrl.com/') WHERE `guid` LIKE 'https://oldUrl.com/%';

Performing this to replace https://example.com to https://newExample.com makes the following changes to the database

guid change

You might want to replace another Column’s Data for your MySQL Database, not only limited to WordPress’ Posts

MySQL Search and Replace Query

UPDATE  `MySQL_Table` SET  `MySQL_Table_Column` = REPLACE(`MySQL_Table_Column`, 'oldString', 'newString') WHERE  `MySQL_Table_Column` LIKE 'oldString%';

MySQL Search and Replace Query

When Should I use MySQL Search and Replace?

Doing a Search and Replace via SQL could be dangerous if you have links that you’re unaware of which shouldn’t be changed. You should Search and Replace only when you’re convinced that you have to change the text in your Database. You should always perform a Database backup before proceeding with any manual changes. This can easily be done through phpMyAdmin:

phpMyAdmin-backup

Get a new cheap cpanel hosting account with unlimited number of MYSQL databases. SSD MYSQL hosting on a greatly discounted price – 40% OFF the regular price – starting from $2.94/mo only!