If you are transferring a Magento site from one server to other, or from your live server to localhost, then you need upload the files backup and then import your database to a newly created database.
Then you edit the app/etc/local.xml file for the DB connection info.
Now even if you enter al the correct info, it gives such errors,
SQLSTATE  Access denied for user ‘username’@’localhost’ (using password: YES)
So, here is a solution to that :