Question

Why did MySQL suddenly stopped on my server?

I am running a ready-made Wordpress droplet. Today my website displayed the dreaded “failed to establish database connection” message. I logged in to the server and noticed that the mysqld daemon doesn’t run in the background, so restarted it and all was fine again.

Question is, why would mysqld randomly stop by itself? I don’t want to find out that the WP website just doesn’t work when a potential client wants to look at it.


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.

What is your Droplet size? Are you using 512MB Droplet?

What comes to my mind is that if MySQL could got killed because it left without available RAM.

As of Ubuntu 16.04, default MySQL is 5.7, which requires at least 1GB of RAM on Droplet.

If you are really using 512MB Droplet I could recommend you upgrading to higher or setting-up swap

Yes, you should look at system logs before come to a conclusion. But there is a 95% chance that this happened due to lack of memory. You’ll have to upgrade your droplet if that’s the case. And while you’re at it you can create a more optimized environment for WordPress using a LEMP setup.

Every droplet I have ever created with an install of Wordpress will eventually crash MySQL, unless I take certain steps.

Mostly, what happens is that Wordpress is barraged with bots trying to login or gain access to your Wordpress account.

A few steps will diminish these attacks to rarely if ever crash MySQL:

  • Install the plugin Login-lockdown
  • Change your Wordpress Login Page (you will need to Google for that, as there is several ways to go about it) basically you are moving your Wordpress login page from wp-login.php to something else (for example mypersonalogin.php)
  • set up swap (as mentioned in previous answers
  • use 6G firewall in your .htaccess https://perishablepress.com/6g/

Lastly, I created a script that will check on MySQL and Apache and restart them if needed:

https://github.com/sierracircle/services-checker

Those things will not completely stop all bots or attacks on your Wordpress site, but they will stop the mindless bots that are searching for basic/common installs of Wordpress, which will make MySQL crash.

For fun, once you install Login-Lockdown, wait for a bit and then view the logs (under settings in Wordpress) and you will see all of the attempts that have been made to access your site. You can see all of the common names and passwords that the bots use to try and login with.