Drush and database credentials from external sources For some specific automation reasons, I use the following snippet in settings.php rather than defining db credentials directly in it.

$databases = array(
  'default' =&gt; array(
    'default' =&gt; array(
      'database' =&gt; $_SERVER['DB_NAME'],
      'username' =&gt; ini_get('mysql.default_user'),
      'password' =&gt; ini_get('mysql.default_password'),
      'host' =&gt; 'localhost',
      'port' =&gt; '',
      'driver' =&gt; 'mysql',
      'prefix' =&gt; '',
    ),
  ),
);


And when I try to use drush, it won't pick up database credentials. How can I give the right database credentials to Drush? Can I define something in drushrc files per project?

The following is what I get from drush status.


  Drupal version         :  7.22
      Site URI               :  http://default
      Database driver        :  mysql
      Database hostname      :  localhost
      Database username      :
      Database name:
      Default theme          :  garland
      Administration theme   :  garland
      PHP configuration      :  /etc/php5/cli/php.ini
      Drush version          :  5.4
      Drush configuration    :
      Drupal root            :  /home/oep/www/dev/docroot 
      Site path              :  sites/default
      File directory path    :  sites/default/files
As you can see, drush is run from command line interface, so it uses cli/php.ini and not regular one. If you feel like keeping password and username in ini file, you need to make sure there are synchronized between WWW and CLI php.ini files.