Use multiple databases on drupal 8

Submitted by editor on Wed, 01/18/2017 - 17:23
Question

How to use multiple databases to move some tables from main database.

Move some tables into another database.

Example:

$databases['default']['default'] = array(
  'database' => 'drupal8_default',
  'username' => 'root',
  'password' => 'THEPASSWORD',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',

  //Add prefix to separate databases
  'prefix' => array(
    //Use a shared database for the users (not recomended, Just for example)
    'users' => 'drupal8_shared.',

    //Move cache into another database
    'cache_bootstrap' => 'drupal8_cache.',
    'cache_config' => 'drupal8_cache.',
    'cache_container' => 'drupal8_cache.',
    'cache_data' => 'drupal8_cache.',
    'cache_default' => 'drupal8_cache.',
    'cache_discovery' => 'drupal8_cache.',
    'cache_dynamic_page_cache' => 'drupal8_cache.',
    'cache_entity' => 'drupal8_cache.',
    'cache_menu' => 'drupal8_cache.',
    'cache_render' => 'drupal8_cache.',
    'cache_toolbar' => 'drupal8_cache.',
  ),
);

//Configure shared database
$databases['shared']['default'] = array(
  'database' => 'drupal8_shared',
  'username' => 'root',
  'password' => 'THEPASSWORD',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

//Configure cache database
$databases['cache']['default'] = array(
  'database' => 'drupal8_cache',
  'username' => 'root',
  'password' => 'THEPASSWORD',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

 

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.