Raphaël
Raphaël

Reputation: 1141

Replace string with mysql

I have a site with a domain "mydomainA.com". I moved to a site "mydomainB.com". The problem: I have a lot of images in the pages that link to "mydomainA.com". I would like to save time and find a MySQL query that replaces all occurrences of a term ... by another to replace all occurrences of "mydomainA" by "mydomainB".

But is that really possible?

Otherwise, I would use php preg_replace edn.

Sincerely,

Upvotes: 0

Views: 95

Answers (3)

Dario
Dario

Reputation: 5333

Probably you are looking for the Replace MySQL command. Combined with an UPDATE just does its job.

Upvotes: 1

Sharique
Sharique

Reputation: 4219

Syntax of replace is

UPDATE table1 SET field1 = REPLACE(field1,'value1','value2')
WHERE field1 LIKE '%value1%'

Check replace function here.

Here is an example

Upvotes: 1

piotrm
piotrm

Reputation: 12366

UPDATE links SET url = REPLACE( url, 'mydomainA.com', 'mydomainB.com' )

http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_replace

Upvotes: 2

Related Questions