Find and Replace Text in MySQL Database


How to Find and Replace Text in MySQL Database using SQL query.

Find and Replace Text in MySQL Database

REPLACE is a function that returns the string text_string with all occurrences of the string from_string replaced by the string to_string, where matching is case-sensitive when searching for from_string.

text_string can be retrieved from the a field in the database table too. Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement.

Example:

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);

update customer_table set company_name = replace(company_name, ‘The Wolf of Wall Street”, ‘The Tiger of Wall Street’);

This MySql query/statement will replace all instances of ‘The Wolf of Wall Street’ to ‘The Tiger of Wall Street’ in the field of company_name of customer_table table.

 

 

One more small and useful query.

Rename or change name of MySQL table.

To rename an existing MySQL table, with or without data in it, it is no problem. One simple command will change the table’s name:

RENAME TABLE mike TO ann;

you can find more here too: mydigitallife.info
Advertisements