# notes on converting ucalgaryblogs.ca to use multi-db

I followed Jim's instructions to get UCalgaryBlogs.ca converted from using a single database (as is the default) to using multiple databases (17 separate databases now) via the premium.wpmudev.org Multi-DB code to prevent growing pains. The single database config is good for getting up and running, but with 300 blogs in the system, table explosion was causing grief on the shared MySQL database server - there were almost 3000 tables, which was making the automated backup script complain a bit.

While reading the documentation, I was rather confused by the term "global" - which appeared to be used in slightly different ways. Eventually, I plugged through, and got it working. The key is to test it all on a local copy of the database before running the migration script on the production server. Thankfully, the script doesn't delete anything, so I was confident that if anything borked I could just back out the multi-db files and revert to single database config without losing anything.

"Global Tables" are tables that will be stored in a shared, common database rather than in each blog's database in one of the 16 databases used by the multi-db code. These are things that are accessed by all blogs on the WPMU install, and include administrative stuff.

In the db-config-sample-16.php file that ships with multi-db, it also mentions "global-db", "globaluser", and "globalpassword" - those are just the database server address, username, and password to use when connecting to the "Global" database containing the "global tables". They used "global-" in these parameters because it's possible to configure each of the 17 databases to use different database servers, different usernames, and different passwords. For simplicity, I used the same database server and account for all 17 databases.

My db-config.php file was edited as follows:

To create the databases, I used the script at http://db-tools.wpmudev.org/db.php and it generated the code below, which I ran on the MySQL server to create the databases:

CREATE DATABASE wpmu_global DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_0 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_1 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_2 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_3 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_4 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_5 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_6 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_7 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_8 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_9 DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_a DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_b DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_c DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_d DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_e DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE DATABASE wpmu_f DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

After copying the db.php and db-config.php files into place as per Jim's instructions, it all Just Workedâ„¢. New content was being stored in the 16 blog databases, and sites were behaving as expected, but with slightly less table explosion bloat as before.

One thing that makes me a little nervous is that the multi-db code isn't core to WordPress, and is part of the premium.wpmudev.org subscription. This means that it can break in the future - there is no obligation for WordPress to continue to work with it, and if for some reason premium.wpmudev.org decides to abandon the plugin or stop updating it, I'm locked into WordPress 2.7. Neither of these made me lose too much sleep. Worst case scenario, I can always recombine the tables from all 17 databases back into a single Ã¼berdatabase, assuming we haven't outgrown the physical limits of a single MySQL database by then.