How can I change an URL inside a field in MySQL?
Solution 1
Use the replace string function in MySQL:
UPDATE MyTable SET textfield = REPLACE(textfield, "http://oldurl.com/", "http://newurl.com")
Solution 2
There's a handy Wordpress plugin that I've used to search and replace in posts pages with grep:
http://urbangiraffe.com/plugins/search-regex/
Jerome Elkins
Updated on July 24, 2022Comments
-
Jerome Elkins almost 2 years
I have a table called "wp-posts" with a field "post-content". This field contains the text for a blog posts. I'd like to change all records to replace an URL for another one.
Imagine that I can have things like:
This is a test and somewhere there's something like <img src="http://oldurl.com/wp-content/somimg.jpg"> and something like <a href="http://oldurl.com/something">a link</a>."
I want it to be
This is a test and somewhere there's something like <img src="http://newurl.com/wp-content/somimg.jpg"> and something like <a href="http://newurl.com/something">a link</a>."
I need to be able to change this for every record in my table without having to open each post in Wordpress and change them by hand. There has to be a way to do this