Share tables across instances (not recommended)
Please note: This procedure could result in unexpected results, depending on which tables you choose to share, including broken version updates and/or security holes.
For instance, if one site is compromised, an attacker could compromise the shared database tables and compromise your other sites. Think about both the settings to be shared and be aware of the risks involved. You can, however, host multiple sites in the same database (with no shared tables) by using site-wide table prefixes.
By using table prefixes on some tables but not others, you can cause multiple Drupal installations to share a set of common tables. One interesting application for this is to share the taxonomy tables (vocabularies, term_data). Another interesting use is to share users across Drupal installations.
In order to use this capability, create two drupal installs in same DB using different database prefixes. In this example, one is prefixed 'master_' and the other 'slave1_'. Then edit the settings.php file of 'slave1_' so that it points some tables to the 'master_'. For sharing users, add the following:
$db_prefix = array(
"default" => "slave1_", // the prefix for tables that are not shared.
"users" => "master_",
"sessions" => "master_",
"authmap" => "master_",
"sequences" => "master_",
"profile_fields" => "master_",
"profile_values" => "master_",
); Note: The actual tables that you will share depends on your installation.
However, the following tables contain data that is highly site specific and therefore should not be shared:
- cache
- variable
There is a limitation in that you can only explicitly specify which tables will be shared and not the other way round. The following may fail (however a recently deleted comment on this page by marcob suggests this has been fixed:
$db_prefix = array(
// Be careful of this setup.
'default' => 'primary_',
'cache' => 'slave1_',
'node' => 'slave1_',
'system' => 'slave1_',
// etc...
);Setup tip for Drupal 5
For Drupal 5+, an easy way to get started with table sharing across instances is to run the installer twice using the same database - it will create the prefixed tables and handle all the initial INSERTS (as with the 'system' and 'menu' tables, etc) for all your different prefixes.
