I'm trying to get drush to work with my test environment, which is actually using a separate database.

so here's my alias in aliases.drushrc.php:

 $aliases['local'] = array(
   'root' => '/my/drupal/root',
   'uri'  => 'http://localhost',

 $aliases['test'] = array(
   'parent' => '@local',
   'databases' => array (
     'default' => 
     array (
       'default' => 
       array (
         'database' => 'test_db',
         'username' => 'test_user',
         'password' => 'test_pwd',
         'host' => 'localhost',
         'port' => '',
         'driver' => 'mysql',
         'prefix' => '',

When I look at the drush site-alias @local and drush site-alias @test the config is read correctly.

When I run drush @test status it gives me the default status. Notice that the username and db are the default, not my test details.

 $ drush @test status
  Drupal version                  :  7.14
  Site URI                        :  http://localhost
  Database driver                 :  mysql
  Database hostname               :  localhost
  Database username               :  default_user
  Database name                   :  default_db
  Database                        :  Connected
  Drupal bootstrap                :  Successful
  Drupal user                     :  Anonymous
  Default theme                   :  sporttracks
  Administration theme            :  seven
  PHP configuration               :  /private/etc/php.ini
  Drush version                   :  5.8
  Drush configuration             :
  Drush alias files               :  /my/home/dir/.drush/aliases.drushrc.php
  Drupal root                     :  /my/drupal/root
  Site path                       :  sites/default
  File directory path             :  sites/default/files
  Temporary file directory path   :  /tmp

So the question is: why is the alias not being read?


This is not supported by Drush, as explained in this issue: https://drupal.org/node/1335626

In brief, the database information stored in an alias file is only used for Drush commands such as sql-sync, sql-cli and so on; a Drush alias will never affect the way that Drupal is bootstrapped. Therefore, Drush core-status will always show you the database info from settings.php, which is where Drupal reads it from.

If you want to force a different database configuration for a given alias, it would be best to use Drupal's multisite feature, and make another settings.php in a sites/test folder. Then, just specify 'test' as the uri for your alternate alias. Should work like a charm. I always prefer to give my local test installations a completely separate copy of the Drupal + contrib code base too, though, in case I want to fiddle with the code on test without interfering with my other local copy's behavior. Using the multisite feature is fine if this is not a concern for you, though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.