≡ Menu

Shell script to restart MySQL server if it is killed or not working

{ 7 comments… add one }
  • simbah ronggo April 23, 2014, 7:35 pm

    #!/bin/bash
    email=’johndoe@doe.com’
    sub_mysql=’mysql proses down and up’
    MYSQL_START=’/etc/init.d/mysql start’
    MYSQL=’mysql’
    PGREP=’/usr/bin/pgrep’
    #check pid
    $PGREP $MYSQL
    if [ $? -ne 0 ]; then
    $MYSQL_START | mail -s “$sub_mysql” $email
    fi

  • Mgreen October 23, 2012, 4:35 am

    Would work better if it check that it could accept commands.

    Something Like….

    mysql -Dmysql -e “SELECT 1;”

    ;)

  • Ed July 15, 2012, 6:59 pm

    Hello

    Thanks for this nice script.
    I’m quite new at server administration, and have 2 questions about your script :
    1- What do you mean by :
    # path to mail program
    MAILCMD=”$(which mail)”
    # path mysqladmin
    MADMIN=”$(which mysqladmin)”

    Do I need to enter the path of both mail and mysql servers ?

    2- If I enter wrong information for the password (and I leave the default intel as question 1), it works …
    So are login and pawd required ?
    Do it works only I 1- is correctly filled ?

    (I’m working with a ovh release 2 (gentoo))

    Thanks
    Ed

  • Meskalyn May 6, 2009, 1:21 am

    Very, very nice script.
    Simple, but so usefull ;)

  • Murat Çabuk April 28, 2009, 9:33 am

    Thank you. Best Shell Script.

  • Ahmet Alp April 23, 2009, 6:42 pm

    Very Good. Thank you some much.

  • Branislav Viest May 27, 2008, 3:11 pm

    very good a simple. thx

Security: Are you a robot or human?

Leave a Comment