Mysql Search and Replace query

Mysql Search and Replace query  is a standard however actually highly effective one, particularly in case you are mining ormysql search and replace filtering knowledge.You can search and replace all situations of a matched string or textual content in a mysql knowledge desk with the assistance of the next query. We will use the mysql update command for this and you we'd like the Table Name, Column Name, the string to look and the String to replace it with.


Update TABLE_NAME SET Column_NAME = REPLACE(Column_Name, 'Search_string', 'Replace_string');


For Instance if you wish to discover and replace a misspelled phrase akin to ‘camputer‘ and replace it with ‘pc‘ within the mysql area identify ‘units‘ and desk identify ‘device_info‘ then the mysql query to look and replace shall be as follows.

Update device_info SET units = REPLACE(units, 'camputer', 'pc');

This will replace all situations of the phrase ‘camputer’ with the phrase ‘pc’ on this area. However you may as well couple this mysql query with a WHERE situation, the syntax for this can be as follows.

Using Mysql search and replace with WHERE :


Update TABLE_NAME SET Column_One = REPLACE(Column_One, 'Search_string', 'Replace_string') the place Column_Two = 'conditional_string';


Here on this instance Mysql query we replace the phrase ‘camputer’ solely the place Column_Two accommodates the string ‘un-filtered’.

Update device_info SET units = REPLACE(units, 'camputer', 'pc') the place device_status = 'un-filtered';

This command will replace all current situations of the phrase ‘camputer’ with ‘pc’ solely the place the corresponding column_two incorporates the time period ‘un-filtered’ or it won't replace it.

You also can run a number of search and replace mysql queries on the similar time, however just remember to are ending every query with a ‘;’ semicolon.

Leave a Reply