I ws just attempting to install/setup wordpress and I was getting the database connection error from wp-config.php.
I had setup mysql with a user of wordpress and left the host as default (connect from any host) which in mysql is %.
I changed this to localhost, and now wp-config.php works fine.
Note, with anyhost (%), mysql command line clients were able to connect to database just fine. For example, mysql -u wordpress blog
Hope this helps.