Error establishing database connection

Hi 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…

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hello, @chandrandivya90

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

  1. 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:

  1. 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! Regards, Alex

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! Regards, Bobby