zoukankan      html  css  js  c++  java
  • MySQL单实例、多实例服务脚本

    一、MySQL单实例服务脚本

    在编写启动脚本之前需要知道MySQL服务的启动与停止命令:

    • 启动  mysqld_safe
    • 停止  mysqladmin 
    #!/bin/sh
    . /etc/init.d/functions
    path="/application/mysql/bin"
    user="root"
    pass="123456"
    
    # 传递参数错误执行的函数
    function usage(){
        echo "$0 {start|stop|restart}"
    }
    
    # 启动服务的函数
    function start(){
        $path/mysqld_safe --user=mysql > /dev/null 2>&1 &
        if [ $? -eq 0 ]
          then
             action "start mysql" /bin/true
          else
             action "start mysql" /bin/false
        fi
    }
    
    # 停止服务的函数
    function stop(){
        mysqladmin --user$user -p$pass shuntdown > /dev/null 2>&1 
        if [ $? -eq 0 ]
          then
             action "stop mysql" /bin/true
          else
             action "stop mysql" /bin/false
        fi
    }
    
    case $1 in
      start)
        start
      ;;
      stop)
        stop
      ;;
      restart)
        stop
        sleep 2
        start
      ;;
      *)
        usage
      ;;
    esac

    二、MySQL多实例服务脚本

    该脚本通过MySQL的sock文件进行判断服务的秦东与否,启动与停止的命令:

    • 启动  mysqld_safe
    • 停止  mysqladmin 
    #!/bin/sh
    port=3306
    user="root"
    pass=123456
    path="/application/mysql/bin"
    sock_path="data/$port/mysql.sock"
    
    
    
    function usage(){
        printf "Usage:/data/$port/mysql {start|stop|restart}
    "
    }
    
    
    # start
    function start(){
      if [ ! -e "$sock_path" ]
        then
          printf "Starting MySQL...
    "
          $path/mysqld_safe --defaults-file=/data/$port/my.cnf > /dev/null 2>&1 &   
        else
          printf "MySQL is running...
    "
          exit  
     fi
    }
    
    # stop
    function stop(){
      if [ ! -e "$sock_path" ]
        then
          printf "MySQL is stoped...
    "
          exit
     else
          printf "Stoping MySQL...
    "
          $path/mysqladmin -u$user -p$pass -S /data/$port/mysql.sock shutdown 
     fi
    }
    
    # restart
    function restart(){
         printf "Restart MySQL...
    "
         stop
         sleep 2
         start
    }
    
    case $1 in
      start)
        start
      ;;
      stop)
        stop
      ;;
      restart)
        restart
      ;;
      *)
        usage
      ;;
    esac

     如果想将上述服务加入开机启动项中,就使用chkconfig命令进行管理:

    • 将上述服务脚本放到/etc/init.d的目录下
    • chkconfig --add multiple_mysql(脚本名称)
    • chkconfig multiple_mysql on
    • chkconfig --list multiple_mysql 

    上述过程实际上就是将启动服务放入到/etc/rc.d/rc3.d目录下。

    作者:iveBoy
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    扁平化职能管理三部曲
    [转载]持续交付和DevOps的前世今生
    敏捷项目管理工具-百度效率云
    敏捷项目管理:基础知识与应用实务
    第8章 “敏捷+”创新创业模式
    第7章 "敏捷+"项目管理
    第6章 迭代循环与项目结束
    第5章 发布循环
    第4章 立项与项目启动
    Windows 2003 + IIS6.0 相关 401.1 或 401.2 等问题解决
  • 原文地址:https://www.cnblogs.com/shenjianping/p/14375203.html
Copyright © 2011-2022 走看看