Question

Error Establishing a Database Connection in WordPress with Ubuntu 16.04.3 NGINX, MARIADB 10, PHP7/7.1 and Wordpress 4.8.2

Posted September 24, 2017 3.9k views
NginxPHPWordPressMariaDBUbuntu 16.04

When I create a new Ubuntu 16.04.3 droplet and I install NGINX, MARIADB and PHP (no matter which versions, all have the same problem) and WordPress I am getting the Error Establishing a Database Connection. Before this error I created +50 servers all the same and since a couple of days I am having this strange problem. Tried almost everything, so I am creating a support ticket for it. When I fill in the Database information (DBname, DBuser, DBpassword) I am getting directly Error Establishing a Database Connection. I am lost for the moment. Someone else with the same problem?

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
2 answers

Have your created a database and user and tested that the connection works outside the scope of WordPress?

Here is a simple bash script to test the connection (adjust as needed)

#!/usr/bin/env bash

WEBROOT=${HOME}/public_html

WPDBHOST=$(cat ${WEBROOT}/wp-config.php | grep DB_HOST | cut -d \' -f 4)
WPDBNAME=$(cat ${WEBROOT}/wp-config.php | grep DB_NAME | cut -d \' -f 4)
WPDBUSER=$(cat ${WEBROOT}/wp-config.php | grep DB_USER | cut -d \' -f 4)
WPDBPASS=$(cat ${WEBROOT}/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4)
WPDBPREF=$(cat ${WEBROOT}/wp-config.php | grep "\$table_prefix" | cut -d \' -f 2);

if [ ! "`mysql -u${WPDBUSER} -p${WPDBPASS} -e 'SHOW DATABASES;' | grep ${WPDBNAME}`" == "${WPDBNAME}" ]; then
  echo "${WPDBNAME} connection failure for ${WPDBUSER}"
  exit
else
  echo "${WPDBNAME} connected"
fi

Hello all,

If you’re unable to access the database using the credentials then the password is likely to be wrong. You can try to reset the passwords for the databases that you’re unable to access.

You can also check our article on How To Debug the WordPress “Error Establishing Database Connection”:

https://www.digitalocean.com/community/tutorials/how-to-debug-the-wordpress-error-establishing-database-connection

Regards,
Alex

by Brian Boucheron
WordPress is one of the most popular open source content management systems in the world. Although it started out focused on blogging, over the years it has developed into a more flexible platform for websites in general. After almost fifteen years of development it is quite polished and robust, yet issues can still come up. If you've recently attempted to load your WordPress-powered website and instead saw a message stating "Error Establishing Database Connection", the cause is most often...