This post is in continuation to Multisite Installation In Drupal 6.
In the previous post mentioned above, we were using separate databases for each site within the same drupal core. There will be requirements where you will be required to have a single database to be shared among multiple drupal site installs. One important requirement being sharing of user access. It will be quite possible that multiple sites setup on same drupal core will want to share the user base. Also, it will be important that user login sessions be shared among those multiple sub sites. Under these circumstances, you will be required to have a single database with some of the tables (if not all) to be shared among the sub sites.
Below are the steps to do that assuming you have one sub site configured like http://example.com/subsite1/ using database ‘example_db’, and you create another sub site like http://example.com/subsite2/ to use same database. Just before running install.php for subsite2 make below mentioned changes to /subsite2/settings.php file by setting $db_prefix as an array like below
# /subsite2/settings.php
$db_url = 'mysql://user:pwd@localhost/example_db';
$db_prefix = array(
'default' => 'subsite2_',
'users' => '',
'sessions' => '',
'authmap' => '',
);
# By setting $db_prefix array like above, we are prefixing every other table with 'subsite2' except for 'users', 'sessions' and 'authmap' tables thereby marking them as shared.
The other way of doing the same thing will be to specify non shared tables like
# /subsite2/settings.php
$db_url = 'mysql://user:pwd@localhost/example_db';
$db_prefix = array(
'default' => '',
'users' => 'subsite2_',
'sessions' => 'subsite2_',
'authmap' => 'subsite2_',
);
# By setting $db_prefix array like above, we are sharing every table between 'subsite1' and 'subsite2' except for 'users', 'sessions' and 'authmap' tables.
Now, you should be ready to run install on subsite2.
Nutshell: The only important point for using a single database between multiple drupal sites with some or none shared tables is the ability to specify shared/non shared tables which is as simple as specifying list of tables within $db_prefix as key/value pairs.
Note: if you want to have single database to be used between multiple drupal sites with no tables shared, just specify table prefix as
$db_prefix = 'subsite2_';