Moving Database one domain to other

2019-03-05 08:05发布

问题:

I was trying to move WordPress website to another domain. Ex: http://www.demo.com to http://www.localhost/demo.... and i have taken xml file backup from c-panel.All the tables are there.And changed url in editor.

When i imported xml file into wordpress dashboard, Pages/posts are not uploading. Only default page and post are there Same problem.

Can Anybody guide me what mistake i am doing and what is the solution ??

Thanks in Advance

回答1:

http://codex.wordpress.org/Moving_WordPress

Navigate to Moving to a New Server.

http://codex.wordpress.org/WordPress_Backups

http://codex.wordpress.org/Backing_Up_Your_Database



回答2:

Here's what I do whenever I have to move a site to a different domain(or from localhost to somewhere on the web):

  1. Make a copy of your files - if you'll be able to zip/unzip a file on both the old and new server, just make a .zip archive with all WordPress files(/wp-admin, /wp-content, /wp-includes and all files in the root directory, otherwise copy them to your computer
  2. Make a Database Copy
  3. On the new server, upload your files(if you did a .zip archive, upload it and unpack it)
  4. Import the database backup on the new server.
  5. Once you've uploaded the database, execute the following SQL code(you can do that from phpMyAdmin for instance)

:

UPDATE `{%TABLE_PREFIX%}options` SET `option_value` = replace(`option_value`, '{OLD_URL}', '{NEW_URL}');
UPDATE `{%TABLE_PREFIX%}postmeta` SET `meta_value` = replace(`meta_value`, '{OLD_URL}', '{NEW_URL}');
UPDATE `{%TABLE_PREFIX%}posts` SET `post_content` = replace(`post_content`, '{OLD_URL}', '{NEW_URL}');
UPDATE `{%TABLE_PREFIX%}posts` SET `guid` = replace(`guid`, '{OLD_URL}', '{NEW_URL}');

Replace the {%...%} placeholders with the corresponding values as follows:

{%TABLE_PREFIX%} is your table prefix, as defined in wp-config.php

{OLD_URL} is the old URL where the site resided. I usually skip the http:// part and the trailing slash(some paths are saved with, some without it, so it's safer to do it that way), so if your site used to be on http://www.demo.com/, you would replace {OLD_URL} with www.demo.com

{NEW_URL} is the new URL where the site will reside. I usually skip the http:// part and the trailing slash, so if your site will reside on http://www.localhost/, you would replace {NEW_URL} with www.localhost. If the new location is a sub-directory(for instance http://www.localhost/example/), you will replace {NEW_URL} with www.localhost/example.

Once you're done with all of that, just go to your new installation, log-in to the dashboard, go to Settings > Permalinks and unless you see a .htaccess permissions error, you're all set :)

If you can't access the DB via phpMyAdmin, or you can't make a back-up of your files, consider using a back-up plugin