Sharing a Database Among Multiple Sites

Drupal makes great efforts to allow you to run multiple sites from the same installation. Because each installation requires its own database, the number of sites you can run on some hosting plans would be limited by the number of databases the web hosting service allows you to make. Some hosting plans allow for only one database. How can people in this situation take advantage of Drupal's multisite configuration features? Fortunately, there is a relatively simple solution. Through the use of table prefixes, you can load the tables for two or more Drupal sites into the same database and instruct each site which prefix to use, thus uniquely identifying the tables within a shared database.

In Figure 6-3, you can see how the tables are prefixed with either db1_ or db2_ and that the list of tables repeats. This is the setup that you can use if you need to use the same database for multiple Drupal installations.

Setting up the database with prefixed tables requires that you edit the database.mysql or database.pgsql file that is used during installation. This would be quite laborious if it had to be done by hand. Thankfully, you can use a script that automates the process.

db l_aggregator_category db l_aggregator_category_feed db l_aggregator_category_item db l_aggregator_item db l_vocabulary_node_types db2_aggregator_category db2_aggregator_category_feed db2_aggregator_category_item db2_aggregator_feed db2_aggregator_item

Figure 6-3. One database with prefixed tables

0 0

Post a comment