Question

MySQL drops out every few days?

  • Posted on September 26, 2012
  • ryan1Asked by ryan1

So I have followed the tutorial to Install Wordpress, Nginx, PHP, and Varnish on Ubuntu 12.04. The process was smooth and easily installed, so no problems there.

The issue is every few days the MySQL connect drops out and when I run the command: $ sudo service mysql start

I get a the following message: $ start: Job failed to start

The other issues is when it first happened, I looked into setting up a script to run in cron every 5 minutes.

# CHECK DATABASE STATUS 
# launch-mysql.sh
ps auxw | grep mysql | grep -v grep > /dev/null
if [ $? != 0 ]
then
    sudo service mysql start > /dev/null
fi

Then added this to $ cron -e

*/5 * * * * ~/launch-mysql.sh

But that is not working either, any thoughts or help would be greatly appreciated.

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.

KFSys
Site Moderator
Site Moderator badge
April 25, 2023
Pinned Answer

Hello all,

When facing with an MySQL issue on your Droplet. Here’s a quick guide to help you troubleshoot the problem:

Check MySQL logs for errors:

Inspect the MySQL error logs for any issues or failures that may have occurred. Usually you can find the log at /var/log/mysql/error.log. If there are any specific error messages, you can further act upon them

Check system logs for process termination:

Sometimes, the MySQL process may be killed by the system due to resource constraints. To check if this happened, inspect the system logs:

  1. grep -E 'oom|kill' /var/log/syslog
  2. grep -E 'oom|kill' /var/log/kern.log

If you find such messages, it’s an indication that your Droplet is running out of resources, and you may need to upgrade your Droplet or optimize your MySQL configuration.

Configure swap space:

If your Droplet is running out of memory, configuring swap space can help alleviate the issue. Swap space acts as a temporary storage location for data when your system runs out of RAM.

You can find more about how to add SWAP to your Droplet here:

https://www.digitalocean.com/community/tutorial_collections/how-to-add-swap-space

Hope that helps!

alexdo
Site Moderator
Site Moderator badge
September 25, 2023

Heya,

I’ll recommend to follow all the steps listed by KFSys in order to fix any errors on your droplet. Then you can create a simple bash script to check if MySQL is running and if not to restart it.

  1. #!/bin/bash
  2. # Check if MySQL is running
  3. sudo service mysql status > /dev/null 2>&1
  4. # Restart the MySQL service if it's not running.
  5. if [ $? != 0 ]; then
  6. sudo service mysql restart
  7. fi

Run this script every 5 minutes using a cron job like this one:

  1. */5 * * * * /home/user/scripts/monitor.sh > /dev/null 2>&1

Hope that this helps!

Swap fixed my issues

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel