Convert WordPress Multi-DB back to Single DB

If you have used the WPMU Multi-DB plugin to fragment your databases from a single instance to 16 or more databases, there may come a time where you need to merge all of those databases back into one. In my case, I want to be able to use Backup Buddy to backup and migrate WordPress blogs. Here are the steps on how to accomplish this massive change. Keep in mind, this is a tutorial  which is written for informational purposes only. I am not responsible for anything that goes wrong.

Create a new database named myDatabase:

mysql> create database myDatabase;

Make a MySQL dump of your existing multisite database:

mysqldump -v -u wpadm -h -pP@ssw0rd --all-databases --skip-lock-tables > WP_DUMP.sql

Next, strip out the MySQL dump lines in the .sql file which tell it to use different databases:

egrep -v "^USE" WP_DUMP.sql > WP2.sql

Next, strip out the MySQL dump lines in the .sql file which tell it to create databases:

egrep -v "^CREATE DATABASE" WP2.sql > WP3.sql

Change what database is currently “used” when it is being imported:

sed -i 's/-- Current Database: `WP_db_00`/use myDatabase;/g' WP3.sql

Import the MySQL dump into the newly created database from step one:

mysql -v -u root -pMyPassword myDatabase < WP3.sql

Last, but not least, remove all files which came with the Multi-DB plugin (db.php and db-conf.php)

* Keep in mind that I spent a lot of time scratching my head over why the sites wouldn’t show up in the Network Admin > Sites list. After all kinds of looking around, I found out that my main global database had been overwritten by another database in the –all-databases array which had the same tables.

One Thought on “Convert WordPress Multi-DB back to Single DB

Post Navigation