Error establishing a database connection

Hi. I’m using 512 mb droplet with with Ubuntu 14.04 x64 and Sentora panel (installed on a fresh Ubuntu droplet). Then I followed these tutorials before I moved my websites on DO: Initial Server Setup with Ubuntu 14.04 and Additional Recommended Steps for New Ubuntu 14.04 Servers. My swap file is 1 GB.

I’m using this doplet for almost 2 months. I have 2 small Wordpress websites. The main one have around 200 visitors a day, the second one have around 60 visitors a day. Since the droplet’s start I’m experiencing Database Errors - Error establishing a database connection. Here is the error I have when I visit wp-admin.php:

I have to login via Putty nad type: sudo service mysql start. At the beginning these errors happened maybe 2-3 times a week. But currently I’m experiencing this problem 2-3 times a day. Maybe more, because I don’t know if there is a MySQL auto restart in Sentora panel. As far as I know, 512 MB droplet with 1 GB swap file should be enough for the traffic I have. At first I thought, maybe it happens when there are many people at the same time. So I opened live view on my Google Analytics page and noticed that in many cases when the error occurs, I had max 3 visitors at the same time. I had moments when there are 10-15 people at the same time surfing through my website’s posts and there are no errors.

I have no idea how to solve this problem. Can anyone help me?

Show comments

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.

I decided to do it the lazy way…created a php script to restart the server…I have set it to run every minute…here is the code…

@$link = mysql_connect('localhost', 'user', 'password');
if (!$link) {
exec("sudo service mysql start");

crontab entry under root

*/1 * * * * php /home/{user}/bin/testconnection.php

Hello, I am having this issue too. Would you mind sharing step-by-step instructions on how to perform all of the operations that solved your problem? I am new at this so while I can ssh into root or use console, I don’t know how to (for instance) mpmprefork, etc.

Thank you so much!

Same problem with 1gb RAM… I don’t understand why :(