?
Solved

MySQL Syntax Problem

Posted on 2014-07-22
11
Medium Priority
?
212 Views
Last Modified: 2014-07-25
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
Comment
Question by:Computer Guy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 42

Expert Comment

by:pcelba
ID: 40211488
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
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40211519
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
 
LVL 3

Author Comment

by:Computer Guy
ID: 40211524
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Expert Comment

by:Randy Poole
ID: 40211537
This would be a per column per table
0
 
LVL 3

Author Comment

by:Computer Guy
ID: 40211546
So there isn't a way to do it all at once?
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40211574
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
 
LVL 3

Author Comment

by:Computer Guy
ID: 40211584
This is for moving Wordpress from domain1 to domain2
0
 
LVL 49

Expert Comment

by:PortletPaul
ID: 40211603
Topic removed: Misc Databases
Topic added: Wordpress
0
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40211617
Paul, may want to add topic MySQL
0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 total points
ID: 40211622
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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question