Skip to main content
Drupal 8

Main navigation

  • Home
    • Question And Answer
    • NEWS
    • Projects
  • Tutorials - Drupal
    • Android
    • Other
User account menu
  • Log in

Breadcrumb

  1. Home

Use multiple databases on drupal 8

By editor , 18 January, 2017
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',
);

 

Tags

  • Drupal 8
  • Code
  • Database
  • Add new comment
Use multiple / external databases in Drupal 8

Comments1

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.

Grey (not verified)

8 years 6 months ago

pgsql

any idea how to get this to work with pgsql? i would like to move the forum to a separate database and access from a different install on another server.

  • Reply

Links

  • Drupal.org
  • Drupal core release cycle
  • Drupal events with ease
  • Unit test with Drupal using PHPUnit (Drupal 10)
  • Tokens for file upload url
  • Tips for Docker
  • CKEditor inline image files usage for custom forms.
  • Install Docker on Linux Mint
  • Install PHP 8.1
  • Drupal Security Best Practices
  • Order and sort items with tabledrag
  • Add a custom service YAML container
  • Apply a patch with composer