I have a table with the following columns in a MySQL database
And the urls are like:
I want to update all the urls to another domain
keeping the name of the file as is.
What’s the query must I run?
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
UPDATE urls SET url = REPLACE(url, 'domain1.com/images/', 'domain2.com/otherfolder/')
UPDATE yourtable SET url = REPLACE(url, 'http://domain1.com/images/', 'http://domain2.com/otherfolder/') WHERE url LIKE ('http://domain1.com/images/%');
Try using the REPLACE function:
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww'); -> 'WwWwWw.mysql.com'
Note that it is case sensitive.
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
You need the WHERE clause to replace ONLY the records that complies with the condition in the WHERE clause (as opposed to all records). You use % sign to indicate partial string: I.E.
means all records that BEGIN with
"...//domain1.com/images/" and have anything AFTER (that’s the
which means all records that contains
in any part of the string…
First, have to check
SELECT * FROM `university` WHERE course_name LIKE '%&%'
Next, have to update
UPDATE university SET course_name = REPLACE(course_name, '&', '&') WHERE id = 1
Results: Engineering & Technology => Engineering & Technology