We often use Find and Replace when editing code or other documents. The MySQL replace string function is just what you need when managing database content.

You should remember that in this instance we are talking about a MySQL function (much like DATE() or MONTH() ) rather then the MySQL Replace statement.

The basic syntax of the MySQL replace string function when doing an UPDATE statement is

UPDATE tbl_name
  field_name = REPLACE(field_name,

For example, lets say you updated your site to https:// but have lots of hard coded internal links in your database. To reolve this you would need to edit each one and swap http:// for https:// .

Another example might be that you changed your domain name or folder structure.

Instead of having to find each entry manually we can make use of the Replace string function and do it all in one query.

UPDATE domains
  url = REPLACE(url,
    'http://', 'https://mysql');

finally lets say you changed your job status and need to update anywhere its mentioned in your news_table table. On top of that we only want that change to happen in the category with an id of 2. we could do something like this.

Notice in this example how we added a condition to the end of the query. Adding a condition is not required but can be useful when you don’t want to update everything.

UPDATE news_table
  SET news_body = REPLACE(news_body,
    'trainee lion tamer', 'qualified lion tamer')
  WHERE news_cat_id = 2;

For more information on MySQL Replace see the official docs