I have a string that is contained inside of a wordpress install (the name of a server) thousands of times, across multiple columns, records and tables.
I'd like to update it with the location of another server - we are moving the content over.
So the source would be something like http://my-server1/some/link/to/something, and I'd want to replace it with http://my-other-server/some/link/to/something. I'm essentially looking to repeat this process for every instance of http://my-server1.
Is there an easy way to do this in MySQL? A tool? Or do I sadly have to update every record problematically?
Thank you,
There is also a Wordpress plugin called Search Regex, which allows running
grep
search and replace across the database.MySQL's REPLACE or replacing the string manually in sql file or db in WordPress is not a good way. WordPress uses serialized fields that may break if you replace some string in them (that was my case)
I used Better Search Replace plugin that worked for me perfectly
Came across this in a google search, but this may help some people. If you know the tables and columns (you could find this using the wildcard search in phpMyAdmin),
Replace bold parts with your own.
If you had a large database you could apply this into a script that could loop through each table and column.
Addittionally to Brad Larson's answer - to set variables like:
And then use it as follows:
A crude (but effective) way of doing it would be to dump the schema into a file, carefully apply the search-and-replace and then re-import.
As a matter of fact I did that today :)
The MySQL dump method would be the best bet if you're happy to re-import the whole database. For anyone that doesn't want to do this - WordPress core installation only actually consists of 11 tables, of which few are content columns, so doing a replace by column would be equally easy. Assuming you don't have loads of plugin tables referencing your link or string this would be your SQL: