Find & Replace Many Different URLs in MySQL for WordPress Site

38 views Asked by At

hopefully my headline made some sense.

I need to update URLs in a WordPress MySQL database. I have a spreadsheet of old URLs (around 400) that need to point to new URLs. All old URLs are down column A, and new ones are down column B.

Is there a way to be able to replace one with the other by way of some voodoo that will replace A1 with B1, A2 with B2 etc in the MySQL database?

Thank team. Hope you are well.

Note: I have not tried anything as yet.

1

There are 1 answers

3
Asgar On BEST ANSWER

Let's suppose you have following columns in your excel sheet;

old_url=Column A & new_url=Column B

old_url new_url
abc_old.com abc_new.com
123_old.com 123_new.com

You can introduce a third column and put formula that matches for following query:

UPDATE table_name t SET t.url='abc_new.com' WHERE t.url='abc_old.com';

Formula in excel would be:

="update table_name t set t.url='"&B2&"' where t.url='"&A2&"';"

This will populate all records accordingly. Then you can execute the queries in your database server