Skip to content

Installing the plugin

Ron Rennick edited this page Jun 20, 2019 · 1 revision

The SharDB plugin contains 3 files that will be placed in the different folders on the web server. You'll also be editing a couple files.

Ususally, I unzipped the plugin package in a spare folder on the web server, made my edits, then moved them in place. You may be more comfortable unzipping the plugin locally, editing the files, then FTPing the files in place. Go with whatever you're more comfortable with.

Edit db-settings.php.

Note this large section near the top that has been commented out.

/* Use this configuration for a hexidecimal based hash 
Ex. you have 256 databases that follow the naming convention acct_wpmuXX
where XX is the hexidecimal hash for the blog DB
// how many characters of hexidecimal hash
$shardb_hash_length = 2;
// what is the prefix of your blog database shards (everything before the hexidecimal hash)
$shardb_prefix = 'acct_wpmu';
// set a string to be used as an internal identifier for the dataset
$shardb_dataset = 'abc';
// do you want to put your primary blog (blog_id 1) in its own 'home' database?
$enable_home_db = true;
// how many, if any, VIP databases do you have?
$num_vipdbs = 5;
// add this to set the write master read priority (default 1)
$shardb_master_read = 99;
// add this if all of your databases are on a local server
$shardb_local_db = true;
// use this function to add a read slave host
add_slave($read_priority, $hostname, $local_hostname, $user, $password); 
// instructions for adding vip blogs at the bottom of this confg filei
*/

This area contains all the possible settings. In this example, we use the bare minimum to get up and running.

  1. Instead of uncommenting the code you want to use, copy the lines and paste them up in the configuration area, like this:
/* Add your configuration here */
$shardb_hash_length = 1;
$shardb_prefix = 'mommiebl_';
$shardb_dataset = 'mb';
  • The $shardb_hash_length of 1 means one character naming scheme for each database. (0 through 9 and a through f).
  • The $shardb_prefix is the web host username I got from my host.
  • Dataset can be anything, it's used internally like a secret key.
  1. Save the file, and put in the same folder where your wp-config.php file is.

Edit wp-config.php

to tell the SharDB migration script what your new database configuration will be.

1- After the define('DB_COLLATE', ...); line, add this line:

require( 'db-settings.php' );

  1. Save wp-config.php

Install shardb-admin.php

Put the shardb-admin.php file in the /wp-content/mu-plugins folder. If you do not have a mu-plugins folder, create it. Code placed in this folder will execute automatically, without activation, and cannot be disabled from the admin area.

In the next step, we'll be migrating tables from the existing single database into our new databases.