I had a similar issue when trying to migrate a Drupal website from one local host to another. From Mac running XAMMP to Windows running WAMP.
This was the error message I kept getting when trying to access the pages of the website.
PDOException: SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
in drupal_get_installed_schema_version() (line 155 of C:\wamp\www\chia\includes\install.inc).
In settings.php, I've changed everything correctly, database name, user and password.
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'mydatabasename',
'username' => 'mydbusername',
'password' => 'mydbpass',
'host' => 'localhost',
'port' => '8889',
'driver' => 'mysql',
'prefix' => '',
),
),
);
After a couple of hours of mindless google searching I've changed the port to a empty value:
'port' => '',
And after that the site loaded properly.