Error establishing database connection

Posted June 7, 2021 281 views
WordPressDigitalOcean Droplets

I have installed my WordPress in Digital ocean. when I tried to open my website (which is under development) the following error is displayed “Error establishing database connection”. i got my domain name from godaddy. What should i do to resolve this issue.....

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

Hi there @chandrandivya90,

It sounds like that your MySQL service might not be up and running. In order to start it you need to first SSH to your Droplet as per the instructions here:

After that try to start the MySQL service:

systemctl start mysql

Let me know how it goes!

Hello, @chandrandivya90

First, you can ensure that the MySQL service is up and running:

  • sudo systemctl status MySQL

You can double-check the database credentials in the wp-config.php file and make sure that they are added correctly in the file, e.g no blank spaces or typos.

It’s worth attempting to connect to the database from the command line, just to make sure. Copy and paste the details right from the config file into the following command:

  • mysqlshow -u database_username -p

You’ll be prompted for a password. Paste it in and press ENTER. If you get an Access denied error, your username or password is incorrect.

You can also double-check the site files/folders permissions and ownerships. to set the correct permissions on the WordPress directories and files:

sudo find /var/www/wordpress/ -type d -exec chmod 750 {} \;
sudo find /var/www/wordpress/ -type f -exec chmod 640 {} \;

Another thing to check is the salt and key values in the wp-config.php file. More information can be found in our tutorial here:

Hope that this helps!

by Lisa Tagliaferri
WordPress is an extremely popular open-source technology and WordPress sites represent 36% of all websites that are currently online. This tutorial is intended for those who are comfortable with system administration or for those who are interested in learning how to administer your own WordPress instance on the server side. In this guide, we’ll install and set up WordPress via LAMP on a Linux Ubuntu 20.04 server.