[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 726
  • Last Modified:

On Ubuntu how do I check if my mySQL server is up and running using CRON and restart it if it is not?

Hi all,

I have a ubuntu 14.04 x64 distribution on a Linode VPS with Apache 2.4.7 and mySQL server 5.5.

It doesn't happen everyday but sometimes, when there are a lot of users connected to my server, the mysql server hangs and doesn't restart on its own. I have to manually restart it using putty but since only I have ssh-based admin access, only I can do that. Basically, if MySQL were to hang with me out of office or sleeping, then all my sites would be offline till I got back and rebooted or restarted the MySQL service manually. I would like to use CRON to create a script that could do one of the following things:

1.

To check every x minutes if MySQL server is up and running and if NOT so then restart it automatically.


OR

2.

To restart it everytime it crashes


Could anyone please assist? I have no experience with CRON or .sh scripts and I have only started using linux last month.

thanks in advance
0
badwolfff
Asked:
badwolfff
1 Solution
 
Dan CraciunIT ConsultantCommented:
It crashes or it hangs?
There's a big difference, cause if it hangs then it's still opened, just not responding (you can verify with ps aux | grep mysqld), and you have to kill it first, then start it.
If it crashes (never happened to me, I would look for problems elsewhere) then you just need to start it.

FWIW, I think you're approaching this the wrong way. If your server hangs regularly then you have a problem either on server's specs (underpowered for your needs) or on the queries you're running. Find the cause and solve it.

Killing Mysql regularly will only help you corrupt your data, in the long run.

HTH,
Dan
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now