Master/Slave

Last updated on
30 April 2025

You are browsing documentation for an older version of Drupal, which is not supported any longer, and the information may not be correct. See current documentation for Contributed modules

The following setup has one master and two slaves with cross failover. If master fails, system will continue in read-only mode. If both slaves fail, system will continue only using the master.

<?php
$databases['default']['master'] = array (
  'database' => 'mydatabase',
  'username' => 'readwrite',
  'password' => 'readwrite',
  'host' => 'master',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
);
$databases['default']['slave'][] = array (
  'database' => 'mydatabase',
  'username' => 'readonly',
  'password' => 'readonly',
  'host' => 'slave1',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
  'readonly' => TRUE,
);
$databases['default']['slave'][] = array (
  'database' => 'mydatabase',
  'username' => 'readonly',
  'password' => 'readonly',
  'host' => 'slave2',
  'port' => '',
  'driver' => 'mysql',
  'prefix' => '',
  'readonly' => TRUE,
);

$databases['default']['default'] = array (
  'driver' => 'autoslave',
  'master' => array('master', 'slave'),
  'slave' => array('slave', 'master'),
);
?>

Help improve this page

Page status: Not set

You can: