Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a WordPress table wp_posts and I'd like to run an UPDATE that will replace a url from my old domain to my new domain.

For example, let's say that one record in the field post_content has the following content:

This is my <a href="">old web</a> site.
<img src=" />

I'd like that to become:

This is my <a href="">old web</a> site.
<img src=" />

I've tried the following query

UPDATE wp_posts AS w` 
SET w.post_content = REPLACE(w.post_content, '', '');

but I don't get any result.

Any idea how to fix it?

share|improve this question
What do you mean by "don't get any result"? Is there an error message, or does the string just not get updated? I just tried your above test case on MySQL 5.1.61 & it worked fine. "Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0" – Phil Mar 13 '12 at 11:24
Found this searching for "mysql longtext find and replace" and I'm also updating all old wordpress posts from an old URL to a new one. Small world. – Hartley Brody Dec 26 '14 at 21:32
up vote 3 down vote accepted

There is an error in your query near

AS w`

Alias name "w" should instead be


Try this:

UPDATE wp_posts AS `w` 
SET w.post_content = REPLACE(w.post_content, '', '');
share|improve this answer
You don't even need to use quotes round the alias. UPDATE wp_posts AS w SET w.post_content = REPLACE(w.post_content, '', ''); works fine – Phil Mar 13 '12 at 11:28
Yes Phil, it can also be used without rounding with quote. I written that way because one quote was missing in the query. – neeraj Mar 13 '12 at 11:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.