Search & replace 'http' to 'https' in database

后端 未结 3 677
遇见更好的自我
遇见更好的自我 2021-02-02 14:18

Using phpmyadmin, I want to run a query that will search my entire database for:

http://example.com

And replace with:

3条回答
  •  时光取名叫无心
    2021-02-02 14:37

    use REPLACE. and if there is a index on the field then the UPDATE can use them

    UPDATE t
         set url = REPLACE(url, 'http:', 'https:')
         WHERE url LIKE '%http:%';
    

    only change example.com

    this will only find row with 'http://example.com'

    UPDATE t
         set url = REPLACE(url, 'http:', 'https:')
         WHERE url LIKE '%http://example.com%';
    

    or this will find all rows with http:// but only change only this http://example.com to https://example.com

    UPDATE t
         set url = REPLACE(url, 'http://example.com', 'https://example.com')
         WHERE url LIKE '%http:%';
    

提交回复
热议问题