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: 
This is done in the same way as in Drupal 7: You can add the database credentials in your settings.php file.

```php
$databases['default']['default'] = array(
  'database' => 'drupal8',
  'username' => 'username',
  'password' => 'password',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

$databases['external']['default'] = array(
  'database' => 'external',
  'username' => 'username',
  'password' => 'password',
  'prefix' => '',
  'host' => 'localhost',
  'port' => '3306',
  'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
  'driver' => 'mysql',
);

```

You will now have two connection options, default and external. You can tell Drupal to use the *external* connection using `\Drupal\Core\Database\Database::setActiveConnection('external')` and switch back to the default one with `\Drupal\Core\Database\Database::setActiveConnection()` once you don't need anymore the *external* connection.
**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.