I have an error: conecting data base.

I dont know what to do. I can see my website and my Bases de datos MySQL® is ok. What do I have to do to fix this.

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.

Hi @etikparati,

When you get Error Establishing Database connection, there are two things that could actually cause it, well more than 2 but if your MySQL is on a local environment then are 2.

MySQL Service

It’s possible your MySQL service to have gone down/be killed by your server due to RAM being insufficient but I’m going ahead of myself.

To check if your MySQL service is down, ssh to your droplet

ssh root@YourDropletIp

Once you are in, type in one of the following 3 (If any of them fail, try with the next one)

service mysql status
service mysqld status
service mariadb status

There are 3 different commands as there is no way for me which exactly you have installed on your droplet. Anyway, if any of them display the service is not running, just type in

service mysql restart

Please note, you’ll need to use the exact service.

Now your MySQL should be working as well as your website. You’ll need to troubleshoot why your service was down though.

Wrong Configuration

It’s possible your website to be experiencing issues if something in the configuration file has changed. If you have made any changes, I’ll recommend reverting them back.

Another solution would be to check the configuration file of your website and replace the database information with the one you have so it’s up to date and correct.

Remote MySQL

If your MySQL service is on a remote server, It’s possible your connection was blocked by the server.

You can allow connections from an IP on port 3306 by doing so

iptables -A INPUT -p tcp -s 0/0 --sport 1024:65535 -d XXX.XXX.XXX.XXX --dport 3306 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables -A OUTPUT -p tcp -s XXX.XXX.XXX.XXX --sport 3306 -d 0/0 --dport 1024:65535 -m state --state ESTABLISHED -j ACCEPT

You’ll need to replace XXX.XXX.XXX.XXX with your actual IP address.

If this doesn’t help, the First two reasons I mentioned can be applied even if your MySQL droplet is a remote one.

Regards, KDSys