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.