Bobcares

Drupal Multisite Shared Database | Setup Tutorial

by | Aug 11, 2022

Drupal Multisite Shared Database is now possible with Drupal 6 and later versions. Bobcares, as part of our Server Management Services, offer solutions to all server inquiries, large or small.

Drupal Multisite Shared Database

With the aid of table prefix, also referred to as $db_prefix from settings.php, we can share tables from databases among Drupal multi-sites. In the settings.php file for the Drupal site, the table prefix is specified.

When it is present Drupal will place the prefix before each table name in the database. So if the table prefix were ‘mysite_’ then Drupal would look for tables with the ‘mysite_’ prefix rather than default table names. This allows more than one Drupal site to share the same database because the table names will not collide with one another. We can have another Drupal instance with another table prefix, e.g., ‘mysite2_’ sharing the database with ‘mysite_’ and indeed many other instances as long as each one has a unique table prefix.

It is a cost-effective alternative when the hosting company only provides one database and paying required for extra databases.

How To Change Table Prefix?

The variable $db_prefix in the site’s settings.php file contains the table prefix for each site. After Drupal is set up, we cannot change the table prefix.

If we must change the prefix or add a new one, we can manually change the $db_prefix line in settings.php. The names of all database tables must be updated, beginning with, the new prefix if the prefix is changed. Otherwise, the website won’t work since it won’t be able to find its database tables. If we attempt to load it without changing the table names, we will probably see the Drupal installation page.

How To Use Table Prefixes To Join Two/More Existing Sites Into A Single Database?

The following steps allow the combination of two or more existing sites into a single database.

  1. Firstly, Create a test database. Then work from the backup.
  2. Change the table names in one (or both) of the databases so that they all begin with a prefix.
  3. Add both sets of tables from the two sites together into a single database now.
  4. Set the $db_prefix variable in both sites’ settings.php files to match the correct prefix for each site.
  5. To check if both websites are functioning properly, try loading them using their respective prefixes.

A Drupal Multisite Shared Database is now available.

[Looking for a solution to another query? We are just a click away.]

Conclusion

To conclude, our Support team walked us through the steps to create a Drupal Multisite Shared Database.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.