How to find and replace text in mysql table

In this quick tutorial i am going to show a very simple mysql query to find specific text and remove the same from selected table column. This is the quickest way to replace text from mysql table.



Suppose you have a table name posts with title and description, These is some common text you have added in each post like you have added any old website link and you want to replace old link with the new link then you don’t need to do manually one by one just run below mysql find and replace query, it’ll replace your old website link with new link within seconds.

TABLE: POSTS

ID TITLE DESCRIPTION STATUS
1 TITLE-1 My first description visit for more info www.iamrohit.in/lab/ 1
2 TITLE-2 My second description visit for more info www.iamrohit.in/lab/ 1
3 TITLE-3 My third description visit for more info www.iamrohit.in/lab/ 0

In the above table there is a link (www.iamrohit.in/lab/) in description column which i have to replace with www.iamrohit.in, For same MySql query will be..

 UPDATE POSTS
 SET DESCRIPTION = REPLACE(DESCRIPTION, 'www.iamrohit.in/lab/', 'www.iamrohit.in');

You can also apply conditional query to replace text form only active posts by WHERE clause.

 UPDATE POSTS
 SET DESCRIPTION = REPLACE(DESCRIPTION, 'www.iamrohit.in/lab/', 'www.iamrohit.in') 
 WHERE STATUS=1;



If you like this post please don’t forget to subscribe my public notebook for more useful stuff