This can be cause for so many reason.
First check the basics:
- database, user, password are correct in wp-config.php (make sure you are using EE configure details or if you have setup your own).
- mysql user has correct permissions
- if using EE you don't have another wp-config.php located in the web root. EE uses wp-config.php in the location above root. WordPress will look for it there if it can't find anything in the root. Caught me out accidently when I uploaded everything.
Where to find MySQL username & Password?
Suppose you have run ee stack install. MySQL username and password are stored in.my.cnf file. The Location of file depends on which user runs ee stack install. i.eroot@vagrant-ubuntu-trusty-32:~# sudo ee stack install command creates file in home directory of sudo user i.e here in /home/harshad/.my.cnf and root@vagrant-ubuntu-trusty-32:~# ee stack install run with root user creates file at /root/.my.cnf location.
Since EasyEngine v3.3.5, the file .my.cnf isn't created anymore. Instead, the new location file is /etc/mysql/conf.d/my.cnf.