如何将本地单点数据库迁移到远程多点数据库?

时间:2017-01-19 作者:Radizzt

我是Wordpress的新手,对于如何从本地服务器获取数据库并将其替换为Wordpress多站点服务器上的数据库,我有点困惑。

我以前曾将数据库从本地替换为服务器,但它是一个多站点。

我通常采取的步骤是:

备份服务器上的数据库导出本地数据库删除服务器数据库上的所有表导入本地数据库转到wp\\U选项更改siteurl的值和站点url的主页尝试此操作时,服务器上的表与本地上的表有很大不同。

我的本地数据库结构如下所示:

enter image description here

通常服务器数据库是相同的,但在本例中不是这样。

服务器数据库结构:

enter image description here

所以我对如何解决这个问题有点困惑。我还能做我通常做的事情吗,或者我还需要采取其他步骤吗?

提前谢谢。

编辑:我认为这有点过于复杂了,我可以在服务器上创建一个新的数据库并指向wp\\u配置。php文件,一切都应该很好

编辑2:没有,它不像我想象的那样工作。继续获取重定向循环错误

编辑3:多亏了@Michael Ecklund! 因为我正在更新主页的数据库,所以我不需要创建新网站,但仍然遵循instruction 他写了,写得很顺利。起初有点困惑,但那是我自己缺乏知识。

编辑4:仅供参考,如果在进行数据库迁移后,您不知何故失去了对仪表板的访问权限。进入主数据库并在*\\u选项(在我的情况下是tenp\\u选项)表中查找wp_user_roles 在option\\u name列下,将该列名称更改为您的站点前缀(在我的情况下是tenp_) 现在,您应该可以再次访问仪表板。

3 个回复
最合适的回答,由SO网友:Michael Ecklund 整理而成

Merging WordPress Standalone Installation with WordPress Multisite Installation

Before You Begin:

  1. Create a new site in your Multisite Network, which will be the site you\'re migrating from the Standalone installation. (Take note of the site ID #, you\'ll need it later.)
  2. You need to make sure that all of the users from the Standalone installation, are created and exist in the Multisite installation.

Step 1 - Backup Databases.

Find the directory on your Web Server which the the Standalone copy of WordPress is installed and the directory on your Web Server which the Multisite copy of WordPress is installed and open the wp-config.php file of both installations. Locate the PHP constant DB_NAME. It contains the name of the database that particular installation of WordPress is using.

  1. Backup the Standalone instillation\'s database.
  2. Backup the Multisite installation\'s database.

Step 2 - Identify the Database Table Prefixes.

By default the database table prefix is wp_.

If you can\'t identify the database table prefix just by examining the database. You can look in the base directory of your WordPress installation and open the wp-config.php file of the site in question and look for a line like $table_prefix = \'wp_\';.

In your situation, it looks like:

  • The Standalone installation\'s database table prefix is the default of wp_.
  • The Multisite installation\'s database table prefix is custom of tenp_.

Step 3 - Export Databases. Import Into Local Environment.

On a local Database Server, create a temporary database for each of these databases. Perhaps to keep things simple, label one database "standalone", and the second one "multisite".

  • Import the Standalone installation\'s database (which you just exported) into the "standalone" database (which you just created) on your local Database Server.
  • Import the Multisite installation\'s database (which you just exported) into the "multisite" database (which you just created) on your local Database Server.

Step 4 - Search and Replace.

This is the step where you would likely replace any necessary URL changes. (http to https), (non-www to www), (add or remove directories from URL), etc.

Perform this task on the "standalone" database you created on your local Database Server.

Remember to change things to how you would like them to be in the Multisite installation (the end result).

For this procedure, you\'re going to need a Database Tool:

  1. WP-CLI :: wp search-replace which is all command line.
  2. Alternatively, if you prefer a GUI, there\'s the Database Search and Replace Script in PHP by interconnect/it.

Step 4.2 - Users and Post Authors

You\'ll want to probably create a note about all the user\'s from your Standalone installation and map the old user ID\'s to the new user ID\'s (from the Multisite installation).

You can simply just create a temporary text file and do something like this:

1 => 4
8 => 23
15 => 9

The numbers on the left are the ID\'s from the Standalone installation and the numbers on the right are the ID\'s on the Multisite installation.

You\'ll then want to update the post_author column of the wp_posts table to update all of the old user ID\'s to the new user ID\'s. Otherwise when view your migrated site from Standalone to Multisite, you\'re going to be one confused kitten. It\'s going to say things on your site were posted by random people and probably even people from different sites in your network. This can be catastrophic if overlooked.

For each of the user ID mappings in your text file, you\'ll want to issue a command much like this into MySQL:

UPDATE wp_posts
SET post_author = \'4\'
WHERE post_author = \'1\'
  • The line SET post_author = \'4\' is the new user ID (the user ID from the Multisite installation)
  • The line WHERE post_author = \'1\' is the old user ID (the user ID from the Standalone installation)

Step 5 - Users and Usermeta

I haven\'t really found a good solution for this step yet. I usually just recreate the users manually in the Multisite installation.

In otherwords, I usually just drop two tables wp_users and wp_usermeta.

If anyone would like to improve on this step feel free to edit and add guidance here.

Step 6 - Update Database Table Names

This step is much like Step 4.

You\'ll want to map old table names to new table names in the "standalone" database on your local Database Server.

This is the step where you will need to know the site ID # from your Multisite installation.

As an example: If your site ID is 15, and your database table prefix use on your Multisite installation is tenp_, then the database table wp_posts would become tenp_15_posts.

Here\'s the MySQL command you can use to update your database table names:

RENAME TABLE `wp_posts` 
TO `tenp_15_posts`;
  • The first line is the old database table name (the database table name from the Standalone installation)
  • The second line is the new database table name (the database table name format to be used in the Multisite installation)

Alternatively, if your database is small enough. You could just export the entire database and open it in a text editor. Then find all & replace. Save it when completed.

Step 7 - Export and Import

Once all of the above changes have been made, export the "standalone" database from your local Database Server.

  1. Import the exported .sql file into the "multisite" database on your local Database Server.
  2. Export the "multisite" database from your local Database Server.
  3. Drop the current Multisite database tables used for your existing Multisite database (not the one on your local Database Server).
  4. Import the .sql file for your "multisite" database you exported from your local Database Server and import it to your database used by your existing Multisite installation (the one you just dropped all the tables from). Essentially just replacing the current Multisite installation\'s database with the modified one which contains the newly migrated Standalone site.

Moving Uploads files from ./wp-content/.

Standalone and Multisite store uploaded files differently. Multisite stores them in ./wp-content/sites/{$site_id}/. Make sure you move your uploaded files appropriately as well.


Changing the Primary Site:

Look for database table wp_site in your Multisite database. Edit the column id and domain appropriately.

You might need to also edit the site_id column in the wp_blogs table.

Also look in wp-config.php for these lines and once again, adjust them accordingly.

define( \'DOMAIN_CURRENT_SITE\', \'www.your-domain.com\' );
define( \'SITE_ID_CURRENT_SITE\', 1 );
define( \'BLOG_ID_CURRENT_SITE\', 1 );

Useful Links:


End.

If anything is confusing, please comment and I\'ll try to clear it up.

SO网友:DGRFDSGN

对于multiwp,数据库的配置确实不同,这些tenp\\u 12是multisite中每个站点的前缀。您在本地运行的站点似乎不是多站点。如果您试图添加另一个站点(非主要站点),我的建议是首先从多站点仪表板添加它,在该仪表板上放置表(即tenp\\u x,其中x类似于您的站点id),然后导入到这些表中。这将要求您预先重命名表名以及collumns,然后您可以按照第6点中的描述配置siteurl的值和站点url的主页。

SO网友:THE WAR OF DESTINY

我一步一步地遵循这个tut,成功地将8个站点迁移出了多站点。对此我非常感激。非常感谢。

在我的例子中,我使用cPanel中的通配符子域将站点设置为子域。我们希望在提取到单个站点后,将站点保留在各自的子域中。换句话说,URL不会改变。这为我们创建了以下额外步骤,我正在分享这些步骤,以防其他人有类似的设置。

暂停要移出多站点的子域的CloudFlare(如果正在使用)

  • 一旦设置了此子域,请返回本教程中的步骤并将新站点安装到子目录中
  • 相关推荐

    在WordPress中将MySQL表格元素显示为页面

    我正试图建立一个WordPress网站,但我需要一个特定的功能,我还没有找到一个插件。我将要刮网站信息和张贴到数据库的信息(这已经处理)。但是,我想创建一个页面来显示所有信息的索引,然后创建一个唯一的页面来显示每个单独的元素(ddbb表的行)。有什么办法可以做到这一点吗??