How to replace strings in MySQL Database?

Can anyone help me replace some strings from WordPress post content? Suppose I added some text to many posts and I want to replace them with another text, how do I do that?. For example, I mention someone’s name in my posts, manager of a company Mr. John Doe. Now the manager changed and the new manager’s name is Mr. Phillip White. So how can I replace all names from Mr. John Doe to Mr. Phillip White in MySQL database at once?

Mr. John Doe => Mr. Phillip White

MySQL has a useful string function called REPLACE which allows you to replace a string with all occurrences.

The syntax of the function is as follows:

REPLACE( field_name, old_string, new_string );

In your case, you need to replace post_content.

UPDATE wp_posts SET post_content = REPLACE( post_content, 'Mr. John Doe', 'Mr. Phillip White' );

You can also add the WHERE condition in your update query.

UPDATE wp_posts SET post_content = REPLACE( post_content, 'Mr. John Doe', 'Mr. Phillip White' )
WHERE post_content LIKE '%Mr. John Doe%';