Question: Can anyone help me to setup connection with multiple databases connection in Drupal 8? I have database on the same server and I want to access it along with default Drupal 8 database.

Answer: 
thank you very much, @googletorp!

here's a slightly more complete example - my code to select users from a D7 database who have created nodes: 

```
\Drupal\Core\Database\Database::setActiveConnection('external');

// Get a connection going
$db = \Drupal\Core\Database\Database::getConnection();

$query = $db->select('users', 'u');
$query->fields('u', array('uid', 'name'));
$query->join('node', 'n', 'n.uid = u.uid');
$query->orderBy('uid');
$users = $query->execute()->fetchAllKeyed();

\Drupal\Core\Database\Database::setActiveConnection();

```
**Update on this topic for the most recent version of Drupal 8 at this time (8.9.13)**:

As mentioned by @acrosman in a comment, you do need to provide two parameters, and not in the order that you might expect. In settings.php, the format is like:

```
$databases['default']['default'] = array(
  'database' => 'database',
  'username' => 'user',
  'password' => 'pass',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
  'collation' => 'utf8mb4_general_ci'
);

```

So if you've added a second database like:

```
$databases['external']['default'] = array(
  'database' => 'database',
  'username' => 'user',
  'password' => 'pass',
  'host' => 'localhost',
  'port' => '3306',
  'driver' => 'mysql',
  'prefix' => '',
  'collation' => 'utf8mb4_general_ci'
);

```

And you want to get a connection to the second database:

```
$connExternal = \Drupal\Core\Database\Database::getConnection('default', 'external');
$results = $connExternal->select('users', 'u')

```

... and so on until ->execute() and fetching the data.

Note that the keys are in reverse order. This is also not set globally with ::getConnection(), so subsequent DB queries will revert to the previous default database.