There are more than likely multiple ways of migrating WordPress on an existing Standalone installation of WordPress into an existing Multisite installation of WordPress. However, this is my way of performing this task. Hope this post helps someone!

I would like to start off immediately by stating, I’m not 100% sure on a good solution for migrating wp_users and wp_usermeta database tables from a Standalone installation into an already existing user base on the Multisite installation. I just recreate the users manually. So if you have a large user base, I cannot currently provide any advice on migrating users.

There’s an idea where you use the WordPress Importer plugin to import your content. Upon importing the content, if the user doesn’t exist, the user is created automatically by the WordPress Importer plugin. I’ve used the importer before, but not for the purpose of migrating users. Not saying this is a good solution for migrating users, just saying it’s a possibility which you could try if migrating users is something which is important to you and your website(s).

Migrating 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_';.

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“.

  1. Import the Standalone installation’s database (which you just exported) into the “standalone” database (which you just created) on your local Database Server.
  2. 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 comment.

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 wp_, then the database table wp_posts would become wp_15_posts.

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

RENAME TABLE `wp_posts` 
TO `wp_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', '' );
define( 'SITE_ID_CURRENT_SITE', 1 );
define( 'BLOG_ID_CURRENT_SITE', 1 );

Useful Links


Original question asked by @Radizzt on WordPress Stack Exchange: moving local database to a multisite wordpress.
Answer to Question: moving local database to a multisite wordpress by @Michael Ecklund on WordPress Stack Exchange.

Related Questions

This article assists in answering all of the following related questions:

  1. [WordPress Development] moving local database to a multisite wordpress asked by: @Radizzt
  2. [WordPress Development] new multisite, old db asked by:
  3. [WordPress Development] migrate comments from old database to new database asked by: @roybatty
  4. [WordPress Development] Copying database tables to new database asked by: @Daniel Morton
  5. [WordPress Development] How to fix unchanged URLs in Database after running serialized search and replace script? asked by: @Barbara
  6. [WordPress Development] Migrating data between local and development server asked by: @Gavin Anderegg
  7. [WordPress Development] How can I migrate from another platform to WordPress (using the same domain) and launch when ready? asked by: @inkedmn
  8. [WordPress Development] Merge two databases: OLD SITE -> NEW SITE asked by: @Salvatore Dibenedetto
  9. [WordPress Development] How to migrate the posts from an old custom legacy blog to a new WordPress website? asked by: @AndreaNobili
  10. [WordPress Development] Migrating Multisite – Database error, missing wp_blogs table asked by: @ThemesCreator
  11. [WordPress Development] Better way to migrate to server? asked by: @Guit4eva
  12. [WordPress Development] 2 website 1 database… Local to online asked by: @Viny76
  13. [WordPress Development] How to change the database prefix in multisite (WPMU) install asked by: @Mike Stumpf

Leave a Reply