Solved

MySQL Syntax Problem

Posted on 2014-07-22
11
191 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
11 Comments
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 21

Expert Comment

by:Randy Poole
Comment Utility
This would be a per column per table
0
 
LVL 3

Author Comment

by:Computer Guy
Comment Utility
So there isn't a way to do it all at once?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 21

Expert Comment

by:Randy Poole
Comment Utility
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
Comment Utility
This is for moving Wordpress from domain1 to domain2
0
 
LVL 48

Expert Comment

by:PortletPaul
Comment Utility
Topic removed: Misc Databases
Topic added: Wordpress
0
 
LVL 21

Expert Comment

by:Randy Poole
Comment Utility
Paul, may want to add topic MySQL
0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 500 total points
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to count occurrences of each item in an array.

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now