tags:

views:

85

answers:

6

I am trying to move a WordPress installation from one server to another one, including all of the SQL data, and the file-system data (photos,template files).

I just have a problem changing the URLs in the database, since I need to replace the new URL with the old one.

I would love to have some suggestions about how can I replace the URLs (maybe there's a rplace statement in SQL?)

Thanks in advance.

+1  A: 

You could simply dump the mySQL in a flat file and open it up in your favorite editor. Than do a find and replace for fully qualified domain name if you are literally change domains. That should take care of WordPress specific URL settings as well, so all your links in pages, posts, sidebars etc. will work. Also be sure to change the local path's recorded in the DB to reflect what the new ones will be as well.

Once your done import the mySQL file in to the new DB and have at it. If something when wrong in transit than you'll definitely know. :)

hsatterwhite
+4  A: 

Several easy ways: How to Move WordPress Blog to New Domain or Location » My Digital Life:

UPDATE wp_options SET option_value = replace(option_value, 
'http://www.old-domain.com', 'http://www.new-domain.com')
 WHERE option_name = 'home' OR option_name = 'siteurl';

and others: How to Find and Replace Text in WordPress MySQL Database using SQL When Changing Domains » My Digital Life

Search RegEx « WordPress Plugins for grepping through posts and pages as a WP plugin-based way to replace image and other URLs in posts and pages.

And there's Moving WordPress « WordPress Codex.

songdogtech
Up vote songdogtech for a great answer and resources!
hsatterwhite
A: 

There is indeed a REPLACE() function in MySQL, but I would recommend doing what hsatterwhite suggests and editing the whole MySQL dump as a flat file before re-importing, not least because the REPLACE() function is case sensitive.

tomfanning
A: 

I think the guy is talking about hard links in his page/ post content. You need to apply @songdogtech's MySQL replace function link this...

UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

This will replace all the links in you post/ page content...

Simon
A: 

1) in your current server, go to phpMyAdmin and export your database

2) open the exported file in your fav code editor, find and replace in the whole document your ex base url (http://www.exdomain.com) with your new one (http://www.newdomain.com)

3) go to the new server, import the SQL file with phpMyAdmin

4) change DB user/pass/host in your wp-config.php

5) transfer via ftp all the files from the old server to the new one

and you should be done.

If you also change the directory path: delete your .htaccess and let Wordpress generate a new one updating the permalink options in the back-end.

This has always worked for me, I use to do this when it's time to move a localhost installation to the final production server.

Hope it helps.

achairapart
Thanks for helping mate!
Maor
+1  A: 

One thing to be aware of is that WordPress stores some of it's data using serialised arrays (some plugins in particular, such as cforms, do this).

In instances where the site URL data may be serialised, simply updating the site URL text can change the length of data in the serialised string, corrupting the data and breaking things.

Dave Coveney has written a php script that takes serialisation into account when doing a search replace in the WordPress database. I have used this script in numerous WordPress migrations and it has been a lifesaver for me.

davemac