未来已来

发布新日志

  • shell脚本实现自动启动mysql服务

    2008-10-12 00:25:33

    mysql 停止启动命令如下:

    # 启动 MySQL Server
    root@localhost root]#  service mysql start
    # 停止 MySQL Server
    root@localhost root]#  service mysql stop
    #停止mysql的另类方法
    root@localhost root]#  pkill mysql
    #重新启动 MySQL Server
    root@localhost root]#  service mysql restart

    根据以上命令实现shell mysql 监控脚本(以下脚本在RH9.0上调试通过)

    #!/bin/bash
    # ------------------------------------------------------------------------
    # Mysql Process Monitor
    # Restart MySql Server When It Goes Down
    # -------------------------------------------------------------------------
    # Copyright (c) 2008 http://www.51testing.com
    # -------------------------------------------------------------------------

    #Mysql start command
    restart_mysql="service mysql start"

    pgrep="/usr/bin/pgrep"

    # mysql daemon name,
    mysql_service="mysqld"


    # find mysql pid
    $pgrep ${mysql_service}


    #if mysql is not runnint
    if [ $? -ne 0 ];then

     # restart apache
     $restart_mysql

    fi


     

Open Toolbar