Replace a text part in MYSQL table

1

With which statement you can replace ONLY part of the text in the table.

I have a table that has several entries with a text such that:

http://miweb.com/textoquequieromantener

and I want it to become this:

https://miweb.com/textoquequieromantener

that is, I want to change http://miweb.com by https://miweb.com keeping the text that comes after that fragment.

I just added SSL to my site and I want to replace the links saved in the database.

    
asked by Pavlo B. 21.11.2017 в 12:52
source

2 answers

1

Edit

You can try something like this:

UPDATE tutabla SET tucampo = REPLACE(tucampo, 'http', 'https') where tucampo like 'http://%';

If you want to modify the entire table, do not use where or filter the results you need . As they say in the comments, my previous proposal would lead to error, with this change it will work correctly

    
answered by 21.11.2017 / 13:06
source
1

Almost self-explanatory:

update tutabla
   set columna = concat('https://miweb.com', substr(columna, length('http://miweb.com') + 1))
 where columna like 'http://miweb.com%';
  • This guarantees that the http://miweb.com is at the beginning of the field, and not anywhere (as in the middle of the text).

Demo: link

    
answered by 21.11.2017 в 13:14