» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > MySQL Forums

MySQL Forums Share Your Ideas and Tips about MYSQL. Ask questions about MYSQL. Table Design and Much More...

Reply
 
Thread Tools Display Modes
  #1  
Old 08-03-2006, 04:52 PM
damien damien is offline
OSP Starters
 
Join Date: Aug 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
damien is on a distinguished road
Default search and replace all database.......

Have a website where we have just changed domain names, but am having a problem because content has been submitted that occasionally uses absolute URL's which has resulted in lots of links through the site pointing to the old domain.

What I want to be able to do is do a search and replace in MySQL that replaces all use of the old domain name with the new one. I've found several search and replace guides around the internet, but they all seem to do a search and replace on a specific field on a specific table like this on;


Code:
UPDATE tablename SET tablefield = replace(tablefield,"findstring","replacestring");

Can anybody tell me how to do a search and replace on an entire database in all fields??
Thanx a million -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 08-03-2006, 04:55 PM
chicken chicken is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
chicken is on a distinguished road
Smile

Follow these steps
  • Dump the database with mysqldump to a text file.
  • Then do a search replace on this dump file. Since it is a text file you can just use any search replace tool that you want.
  • Then import the dump file to the DB again and you should be set.
If your DB is so big that you can't open the dump file in a normal editor you will probably have to use some search replace tool like sed or PERL.
Since I'm a PERL man I would do:

Code:
perl -p -i.bak -e 's/oldstring/newstring/g' yourDumpFile
That will substitute all occurances of oldstring to newstring in yourDumpFile and also save a backup file callec yourDumpFile.bak. If you don't want a backup file you can omit the .bak in the argument.

Hope it helps
Bye buddy -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 11:12 AM.