Wordpress "Error establishing a database connection" on fresh install

Posted December 20, 2013 9.4k views
I played with this for a couple of hours and hit the wall. Wordpress is giving me "Error establishing a database connection." I have a fresh LEMP install with Debian 7. I created a new MySQL user and a new database for Wordpress as listed in one of the tutorials here. I can log into MySQL with the new user credentials so I know the password I wrote down is correct. I am 100% certain that the wp-config-php database authentication credentials are correct. If I change the user and the password in wp-config.php to the MySQL root user the error does not go away. When I run this PHP script with my user credentials I can connect to the database: $db = @mysql_connect('localhost', 'username', 'password'); if (!$db) echo "connection failed"; else echo "connection succeeded"; I have even remade the wp-config.php from the "sample" file just to make sure something critical wasn't damaged elsewhere. I tried replacing "localhost" with my droplet IP address (don't have a domain name yet). So I know that my username and password are good. File permissions for wp-config.php couldn't possibly be a problem? I mean, the PHP file is running and reporting an error. Could it be that the database is corrupt although this little PHP connection tester is working? Do I need to put something specific in place of "localhost" for Wordpress to work?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
4 answers
@EmilJacobs: Is MySQL running?
sudo ps wwuax | grep mysql
If not, start it:
sudo service mysql start
and add swap: or
by Etel Sverdlov
Linux swaps allow a system to harness more memory than was originally physically available. Here's how to set up a linux swap file on Ubuntu 12.04
Does the database not connect at all? Or, does it connect for a little while and then crash? Have you tried rebooting your droplet and/or MySQL?
SOLVED: I configured the MySQL user wrong. It's working now. Thanks.
And how did you solve it? The world (well, that part that has the same issue) would like to know.