Solved

MySQL Syntax Problem

Posted on 2014-07-22
11
207 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
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

 
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 500 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
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).
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

691 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