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.

Syntax:

Example:

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 :

Syntax:

Example:

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

Engineer, Programmer, Internet Entrepreneur, Blogger, SEO & Wordpress Fanatic, Founder of BornVirtual.com and many more...
Hey, lets Connect on Facebook | Twitter | Google+ | LinkedIn | RSS

Speak Your Mind

*