Mysql Search and Replace query

Mysql Search and Replace query  is a common but really powerful one, especially if you are mining ormysql search and replace filtering data.You can search and replace all instances of a matched string or text in a mysql data table with the help of the following query. We will use the mysql update command for this and you we need the Table Name, Column Name, the string to search and the String to replace it with.



For Instance if you want to find and replace a misspelled word such as ‘camputer‘ and replace it with ‘computer‘ in the mysql field name ‘devices‘ and table name ‘device_info‘ then the mysql query to search and replace will be as follows.

This will replace all instances of the word ‘camputer’ with the word ‘computer’ in this field. However you can also couple this mysql query with a WHERE condition, the syntax for this will be as follows.

Using Mysql search and replace with WHERE :



Here in this example Mysql query we replace the word ‘camputer’ only where Column_Two contains the string ‘un-filtered’.

This command will replace all present instances of the word ‘camputer’ with ‘computer’ only where the corresponding column_two contains the term ‘un-filtered’ or it will not replace it.

You can also run multiple search and replace mysql queries at the same time, but make sure that you are ending each query with a ‘;’ semicolon.

About Mazhar

Computer Science Engineer, Cloud Architect, Programmer, Currently Employed as the Head of E-Commerce at one of India's largest Men's Apparel Brand...
Hey, lets Connect on Facebook | Twitter | Google+ | LinkedIn | RSS

Speak Your Mind