Solved

MySQL Syntax Problem

Posted on 2014-07-22
11
195 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
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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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 48

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
Developer portfolios can be a bit of an enigma—how do you present yourself to employers without burying them in lines of code?  A modern portfolio is more than just work samples, it’s also a statement of how you work.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The viewer will learn how to count occurrences of each item in an array.

896 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

18 Experts available now in Live!

Get 1:1 Help Now