script for to stop mysql process

Discussion in 'Database' started by raghu88, Mar 21, 2013.

  1. raghu88

    raghu88 New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi to all,

    Any one help me out,

    i want a script to stop mysql process(without using kill command).


    Help me out.

    Thanks in advance.
  2. laurentv

    laurentv New Member

    Messages:
    25
    Likes Received:
    2
    Trophy Points:
    3
    to stop mysql
    service mysqld stop
    Rob likes this.
  3. Rob

    Rob Administrator Staff Member

    Messages:
    573
    Likes Received:
    184
    Trophy Points:
    43
    Yup.. either that or
    /etc/init.d/mysql stop
  4. akbarali

    akbarali New Member

    Messages:
    16
    Likes Received:
    2
    Trophy Points:
    3
    Hello raghu88

    To automatically start or stop mysql you can use the following link which has provided all the necessary details and command of how to do it.

    Thanks...Go to below link.

    dev.mysql.com/doc/refman/5.1/en/automatic-start.html
  5. taiavatar

    taiavatar New Member

    Messages:
    9
    Likes Received:
    1
    Trophy Points:
    3
    you can use /etc/init.d/mysqld stop
  6. Ghulam Yaseen

    Ghulam Yaseen New Member

    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    1
    Copy the code below highlighted in blue , save it in a file and execute for output. There are 2 variables mysqld_file and mysqld_safe_file where the path of mysqld and mysqld_safe executables have to be configured based on your installation.

    ################################################################################
    # Configure MySQL commands mysqld and mysqld_safe path here.
    # Ex. mysqld_file="/usr/sbin/mysqld"
    # mysqld_safe_file="/usr/bin/mysqld_safe"
    ####################################################################################
    mysqld_file="/usr/sbin/mysqld"
    mysqld_safe_file="/usr/bin/mysqld_safe"
    #################################################################################
    echo -e "\n`date` : $0 is being executed.\n"
    ls -ltrh $mysqld_file >> /dev/null;
    if [ $? -eq 1 ]
    then
    echo -e "`date` : $mysqld_file not present.Please verify your MySQL installation"
    echo " "
    exit
    fi
    if [ `whoami` != 'root' ]
    then
    echo -e "`date` : You have to be a root user to start MySQL."
    echo " "
    exit
    fi
    pid=`ps -ef|grep "$mysqld_file" |grep -v 'grep' |awk '{print $2}'`
    if [ -z $pid ]
    then
    echo -e "`date` : MySQL database process is not running."
    echo " "
    exit
    else
    echo -e "`date` : MySQL process is running. PID - $pid - Stopping now. Please wait. It may take few minutes"
    fi
    kill $pid
    if [ $? -eq 0 ]
    then Status="Success"
    else Status="Failure"
    fi
    sleep 2
    echo -e "------------------------------------------------------------------"
    echo -e "`date` : MySQL Shutdown is : $Status"
    echo -e "------------------------------------------------------------------"
    echo " "
    #################################################################################

    Regards
    -----
    LinuxFreakz

Share This Page