MySQL replaces the specified field string in batches

Source: Internet
Author: User

MySQL batch replacement is a feature that we often use. Sometimes, when the site contains sensitive words, it will cause us trouble. However, when the amount of information is large, it is unrealistic to search and modify an article.

It is easy to use MySQL for batch replacement. Released here for reference.

MySQL batch replace a specified field string statement

 
 
  1. UPDATE data table name SET
  2. Field name = replace (field name, 'replacement string', 'replace ')
  3. WHERE setting conditions;
  4.  

For example, replace "Search Engine Optimization" In Wordpress articles with "search engine marketing", and replace the statement:

 
 
  1. UPDATE wp_posts SET
  2. Post_content = replace (post_content, 'search engine optimization', 'search engine marketing ');
  3.  

You can also add replacement conditions in the statement. For example, you can only replace the content with a limited ID less than 200:

 
 
  1. UPDATE wp_posts SET
  2. Post_content = replace (post_content, 'search engine optimization', 'search engine marketing ')
  3. Where id <200;
  4.  

You can set replacement conditions based on your needs.
 

MySQL string addition function usage example

Mysql query case

How to query duplicate records in MYSQL

How to Implement MySQL full-text Query

Example of the number of MySQL query results

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.