Export a specific non-default database using drush sql-dump My Drupal 7 site connects to multiple databases using a $databases array like this:

$databases = [
  'default' =&gt; [
    'default' =&gt; [
      'database' =&gt; 'examplecom',
      'username' =&gt; 'example',
      'password' =&gt; 'sostrongpassword',
      'host' =&gt; '',
      'port' =&gt; '',
      'driver' =&gt; 'mysql',
      'prefix' =&gt; '',
    ],
  ],
  'nondefault' =&gt; [
    'default' =&gt; [
      'database' =&gt; 'notdefaultdb',
      'username' =&gt; 'notdefaultuser',
      'password' =&gt; 'notdefaultpass',
      'host' =&gt; '',
      'port' =&gt; '',
      'driver' =&gt; 'mysql',
      'prefix' =&gt; '',
    ],
  ],
];


Ideally I want to be able to do something like drush --database-key=nondefault sql-dump &gt; myfile.sql but I don't see a way in drush to do that. Is it possible?

I tried creating a custom script to do this like:

drush_sql_bootstrap_further();
db_set_active('nondefault');
$sql = drush_sql_get_class();
return $sql-&gt;connect(FALSE);


And then calling that script with drush scr foo.php but the sql connect (or any other command) seem to work against the default database.
According to the Drush 8 docs, there is a --database=key option that does what you want.

I've verified it against a D8 site with multiple databases using the command:

drush @dev sql-dump --database="blog_import" &gt; ~/tmp/blog_import.sql


The drush sql-cli command also has the same option so you should be able to import the dump using a command like:

drush @dev sql-cli --database="blog_import" &lt; ~/tmp/blog_import.sql