When you need to manually migrate a WordPress installation from one domain to another, you must perform some several database queries in order to make the new installation properly working.
A common misconception is that it is enough to just change the site_url
and home
values in the WP admin panel, but that’s just not.
Those are two core value WordPress uses to build its own base_url, but when a site is already filled with content, there are a few more tables involved in the process (wp_posts, wp_comments and wp_postmeta) and in which WordPress stores data. if you don’t update those too, you’ll end up with a site with all media still pointing to the old domain as well as links and other data.
So here are the life-saving SQL queries you need to perform when doing a manual transfer. You only have to change the placeholders below, from:
original.domain.com
to new.domain.com
NOTE: if you’re migrating a site from a local enviroment (localhost), skip the last query and execute its alternative labeled “Alternative Query 7 for migrations from localhost enviroments”.
-- Query 1: update the wp_options table
UPDATE wp_options SET option_value = REPLACE(option_value, 'http://original.domain.com', 'https://new.domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
-- Query 2: update the wp_posts table
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://old.domain.com', 'https://new.domain.com');
-- Query 3: update the wp_posts table
UPDATE wp_posts SET post_excerpt = REPLACE (post_excerpt, 'http://old.domain.com', 'https://new.domain.com');
-- Query 4: update the wp_postmeta table
UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://old.domain.com','https://new.domain.com');
-- Query 5: update the wp_comments table
UPDATE wp_comments SET comment_content = REPLACE (comment_content, 'http://old.domain.com', 'https://new.domain.com');
-- Query 6: update the wp_comments table
UPDATE wp_comments SET comment_author_url = REPLACE (comment_author_url, 'http://old.domain.com','https://new.domain.com');
-- Query 7: update the wp_comments table
UPDATE wp_posts SET guid = REPLACE (guid, 'http://old.domain.com', 'https://new.domain.com') WHERE post_type = 'attachment';
-- Alternative Query 7 for migrations from localhost enviroments
-- UPDATE wp_posts SET guid = REPLACE (guid, 'http://old.domain.com', 'https://new.domain.com');
Important notice
The most important reference when moving WordPress from one domain to another, is this CODEX page here.
Also consider that in some cases, as metioned before, plugins may store serialized data in the wp_postmeta table. In order to prevent a potential break within that data, follow the following CODEX advice:
If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break. To avoid that serialization issue, you have three options:
- Use the Velvet Blues Update URLs or Better Search Replace plugins if you can access your Dashboard.
- Use WP-CLI’s search-replace if your hosting provider (or you) have installed WP-CLI.
- Use the Search and Replace for WordPress Databases Script to safely change all instances on your old domain or path to your new one. (** only use this option if you are comfortable with database administration ** )
Note: Only perform a search and replace on the wp_posts table.
Note: Search and Replace from Interconnectit is a 3rd party script
A WordPress Commenter
If you’re not familiar with queries try the Search and Replace plugin, wordpress.org/extend/plugins/search-and-replace
Paul S
Great! All migration related queries at one place
DONOVAN
Many free plugin served the same purpose for beginners. That must be mentioned here..
ufizutmekezes
[url=http://slkjfdf.net/]Akovexoi[/url] Ugoyac sit.dyuz.pushpendra.space.vsn.zd http://slkjfdf.net/
zoritoler imol
Hmm it looks like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well am an aspiring blog blogger but I’m still new to everything. Do you have any tips for first-time blog writers? I’d definitely appreciate it.
Pushpendra
just one piece of advice try to write on trending topics.
zoritoler imol
It’s actually a great and useful piece of information. I’m glad that you shared this useful information with us. Please stay us up to date like this. Thank you for sharing.
vorbelutr ioperbir
This is really interesting, You’re a very skilled blogger. I have joined your feed and look forward to seeking more of your great post. Also, I have shared your site in my social networks!
zoritoler imol
I am always browsing online for articles that can assist me. Thanks!