Drupal multisite with shared tables

Drupal allows you to create multiple sites sharing some or all of the same code and optionally sharing some database tables.

The documentation for the Drupal settings file
http://api.drupal.org/api/file/sites/default/settings.php/5/source

includes the following

<?php
/*
* To have all database names prefixed, set $db_prefix as a string:
*
*   $db_prefix = 'main_';
*
* To provide prefixes for specific tables, set $db_prefix as an array.
* The array's keys are the table names and the values are the prefixes.
* The 'default' element holds the prefix for any tables not specified
* elsewhere in the array. Example:
*
*   $db_prefix = array(
*     'default'   => 'main_',
*     'users'     => 'shared_',
*     'sessions'  => 'shared_',
*     'role'      => 'shared_',
*     'authmap'   => 'shared_',
*     'sequences' => 'shared_',
*   );
*/
?>

This allows you to have several related sites which might (for example) share user tables so that users have single sign on, while having different tables for content.

Note that to get this functionality the sites have to share a single database.

I've never quite seen the point of multi site Drupal installs for unrelated projects, in theory this could save on upgrade work - but in practice I'd rather have the greater control that separate install gives you.

For a family of websites I can see a multi site install with some shared data being a really powerful and effective solution.

Tags

Comments

database prefix

Since I wrote this post I have discovered that it is possible to use a database prefix

i.e.

<?php
*   $db_prefix = array(
*    
'default'   => 'site1.',
*    
'users'     => 'shared.',
*    
'sessions'  => 'shared.',
*   );
*/
?>

This would cause all tables to be in the site1 database - apart from users and sessions which would be in the "shared" database.

see
http://drupal.org/node/291373 (Multi-site with single codebase, different content databases, shared user database, shared sign-on)

Post new comment

Got something to add - just enter a comment
all other fields are optional.

Your email address will not be published.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.