• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

MySQL Syntax Problem

Hi,

I need to replace all instances of domain1.com in my database with domain2.com

I tried this:

SELECT REPLACE('domain1.com', 'domain2.com'); and no luck.

Any ideas?
0
Computer Guy
Asked:
Computer Guy
1 Solution
 
pcelbaCommented:
You have to specify 3 parameters:

SELECT REPLACE('***domain1.com***', 'domain1.com', 'domain2.com');

The original text is table column obviously:
 SELECT REPLACE(SomeTextColumn, 'domain1.com', 'domain2.com') AS OutputName
   FROM SomeTable

The function syntax is:
REPLACE(str, from_str, to_str)

More info: http://www.w3resource.com/mysql/string-functions/mysql-replace-function.php

MySQL also provides REPLACE command: http://www.mysqltutorial.org/mysql-replace.aspx
0
 
Randy PooleCommented:
I think you would want to replace so issue an update
Update YourTable Set yourcolumn=REPLACE(yourcolumn,'domain1.com','domain2.com')

Open in new window

0
 
Computer GuyAuthor Commented:
Trying this: SELECT REPLACE('domain1.com', 'domain1', 'domain2');

How can I do that for all of the tables in the DB on one clip?
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
Randy PooleCommented:
This would be a per column per table
0
 
Computer GuyAuthor Commented:
So there isn't a way to do it all at once?
0
 
Randy PooleCommented:
I suppose you could write a procedure to do it that queries all the tables, then loops through those, and  that routine queries all the string fields which builds and executes a sql statement.  But that would probably take a bit of time.  How many tables/fields does this need to be done to?
0
 
Computer GuyAuthor Commented:
This is for moving Wordpress from domain1 to domain2
0
 
PortletPaulCommented:
Topic removed: Misc Databases
Topic added: Wordpress
0
 
Randy PooleCommented:
Paul, may want to add topic MySQL
0
 
Randy PooleCommented:
Have you looked at this?  This will give you step by step instructions on how to do it, since WP already has scripts for this type of maintenance.

http://codex.wordpress.org/Moving_WordPress#Moving_WordPress_to_a_New_Server
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now