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

后端 未结 3 720
遇见更好的自我
遇见更好的自我 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:38

    Warning, the answers given so far will mess up serialized data!

    For example, say your site stores serialized data in a row with the URL in it, like this:

    a:1:{i:0;s:19:”http://example.com”;}
    

    Notice that the value of this item has 19 characters, and is denoted by s:19 in the array.

    If you replace content using a SQL query, the same row on your new environment would end up like this:

    a:1:{i:0;s:19:”https://example.com”;}
    

    But after this change, the value is now 20 characters long meaning s:19 is incorrect. This invalidates the array and the entire row.

    So either you make sure your SQL statements deal with serialized data, or if you happen to be using WordPress then there are a few options to search using PHP so as to not break the serialized rows:

    • The Better Search Replace plugin automatically handles serialized data
    • The Search and Replace plugin offers an option which handles serialized data

    Taken and adapted from: https://wpengine.com/support/wordpress-serialized-data/

提交回复
热议问题