HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

MySQL UPDATE to replace text in LONGTEXT field

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
longtextfieldupdatetextreplacemysql

Problem

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 old web site.


I'd like that to become:

This is my old web site.


I've tried the following query

UPDATE wp_posts AS w` 
SET w.post_content = REPLACE(w.post_content, 'my-old-site.com', 'my-new-site.com');


but I don't get any result.

Any idea how to fix it?

Solution

There is an error in your query near

AS w`


Alias name "w" should instead be

`w`


Try this:

UPDATE wp_posts AS `w` 
SET w.post_content = REPLACE(w.post_content, 'my-old-site.com', 'my-new-site.com');

Code Snippets

UPDATE wp_posts AS `w` 
SET w.post_content = REPLACE(w.post_content, 'my-old-site.com', 'my-new-site.com');

Context

StackExchange Database Administrators Q#14897, answer score: 6

Revisions (0)

No revisions yet.