各位用户为了找寻关于老鸟带你开发专业规范的MySQL启动脚本的资料费劲了很多周折。这里教程网为您整理了关于老鸟带你开发专业规范的MySQL启动脚本的相关资料,仅供查阅,以下为您介绍关于老鸟带你开发专业规范的MySQL启动脚本的详细内容

每一个合格的Linux运维人员都应该做到熟练或精通Shell脚本编程,因为Shell脚本语言差不多是所有编程语言里最简单的语言,如果Shell脚本不行,意味着运维之路可能还没开始就将要终结。——老男孩老师

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 #!/bin/bash # chkconfig: 2345 64 36 #配置系统自启动 # description: A very fast and reliable SQL database engine. ############################################################## # File Name: mysqld # Version: V1.0 # Author: oldboy # Organization: www.oldboyedu.com # Created Time : 2018-06-05 08:58:19 ############################################################## #引入系统函数库 . /etc/init.d/functions   #基础路径定义 basedir='/application/mysql' bindir='/application/mysql/bin' lockdir='/var/lock/subsys'                    lock_file_path="$lockdir/mysql" mysqld_pid_file_path='$basedir/data/`uname -n`.pid'   #成功提示函数 log_success_msg(){   #action为特殊的提示函数,$@为所有参数。   action "SUCCESS! $@" /bin/true } #失败提示函数 log_failure_msg(){   action "ERROR! $@" /bin/false  }   #mysql启动函数 start(){   echo $"Starting MySQL"   #测试mysqld_safe是否可执行   if test -x $bindir/mysqld_safe   then     #后台执行启动mysql命令     $bindir/mysqld_safe &>/dev/null &     #获取返回值     retval=$?     #判断返回值是否为0     if [ $retval -eq 0 ]     then       #调用成功提示函数。       log_success_msg "mysql Startup"       if test -w "$lockdir" #判断锁目录是否可写。       then         touch "$lock_file_path" #创建锁文件。       fi       return $retval #给返回值是专业的表现。     else       log_failure_msg "MySQL Startup" #调用失败函数提示。       return $retval     fi   else     log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"   fi } #停止MySQL函数。 stop(){   #判断mysql pid file大小是否为0。   if test -s "$mysqld_pid_file_path"   then     #读取pidfile     mysqld_pid=`cat "$mysqld_pid_file_path"`     #判断mysql pid对应的进程是否存在。     if (kill -0 $mysqld_pid 2>/dev/null)     then       echo $"Shutting down MySQL"       kill $mysqld_pid #停止MySQL命令。       retval=$?       if [ $retval -eq 0 ]       then         log_success_msg "MySQL Stop" #调用停止成功函数。         if test -f "$lock_file_path"         then           rm -f "$lock_file_path" #删除锁文件。         fi         return $retval       else         log_failure_msg "MySQL Stop."         return $retval       fi     else       log_failure_msg "MySQL server process mysqld_pid is not running!"       rm "$mysqld_pid_file_path"     fi   else     log_failure_msg "MySQL server PID file is null or not exist!"   fi } #接收传参判断并执行相应函数。 case "$1" in   start)     start     retval=$?     ;;   stop)     stop     retval=$?     ;;   restart)     stop     sleep 2 #这里很重要,要休息一下。     start     retval=$?     ;;   *)     echo $"Usage:$0 {start|stop|restart}"     exit 2 esac exit $retval  #执行脚本后,有返回值才更专业。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

原文链接:https://blog.51cto.com/oldboy/2124950