[MySQL] How to find and replace text in a MySQL database - MySQL string replace

Thảo luận trong 'Hướng Dẫn' bắt đầu bởi TechBuba, 26/6/17.

  1. TechBuba Nhà Báo (Báo Đời)

    The example query below updates the "content" and "description" fields of the "content" table. Obviously your database will have different fieldnames and you may only want to update one field, or maybe update more fields. Simply modify the query to suit.

    Mã:
    UPDATE your_table
    SET your_field = REPLACE(your_field, 'articles/updates/', 'articles/news/')
    WHERE your_field LIKE '%articles/updates/%'

    Mã:
    UPDATE content
    SET description = REPLACE(description, 'http://famspam.com/facebox', 'http://defunkt.io/facebox/'),
    content = REPLACE(content, 'http://famspam.com/facebox', 'http://defunkt.io/facebox/')
    WHERE description LIKE '%http://famspam.com/facebox%'
    OR content LIKE '%http://famspam.com/facebox%'
     
     
  2. Bình Luận Bằng Facebook