Mysql – Search & replace ‘http’ to ‘https’ in database

MySQLphpmyadminsql

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

http://example.com

And replace with:

https://example.com

My SQL knowledge is limited, maybe something like:

UPDATE ?? = REPLACE(??, 'http://example.com', 'https://example.com');

The database is over 1gb, so what can I run that will not crash the server.

Update: Note that while there are other answers posted here on SO that deals with search and replace, they don't seem to cover the entire database.

Best Answer

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:%';