此文是Mysql 5.7的 Deamon 文件,配置多实例遇到pid不生效的问题,通读了下,贴出来,有少量自己加的注释。

#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind# MySQL daemon start/stop script.# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start:  2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
#   [mysqld]
#   basedir=<path-to-mysql-installation-directory>
# - Add the above to any other configuration file (for example ~/.my.ini)
#   and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable
#   below.
#
# If you want to affect other MySQL variables, you should make your changes
# in the /etc/my.cnf, ~/.my.cnf or other MySQL configuration files.# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.basedir=/data/opt/mysql
datadir=/data/opt/mysql/data3307# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"# The following variables are only set for letting mysql.server find things.# Set some defaults
mysqld_pid_file_path=
#如果$basedir 字符串为空
#则定位到默认位置
#basedir=/usr/local/mysql
#datadir=/usr/local/mysql/data
#bindir=/usr/local/mysql/bin
#sbindir=/usr/local/mysql/bin
#libexecdir=/usr/local/mysql/bin
if test -z "$basedir"
thenbasedir=/usr/local/mysqlbindir=/usr/local/mysql/binif test -z "$datadir"thendatadir=/usr/local/mysql/datafisbindir=/usr/local/mysql/binlibexecdir=/usr/local/mysql/bin
elsebindir="$basedir/bin"     #okif test -z "$datadir"thendatadir="$basedir/data"fisbindir="$basedir/sbin" #oklibexecdir="$basedir/libexec" #ok
fi# datadir_set is used to determine if datadir was set (and so should be
# *not* set inside of the --basedir= handler.)
datadir_set=#
# Use LSB init script functions for printing messages, if possible
#
lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then #文件存在,且是正规文件. $lsb_functions
elselog_success_msg(){echo " SUCCESS! $@"  #$@ 所有参数列表}log_failure_msg(){echo " ERROR! $@"}
fiPATH="/sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"  #启动加载环境变量
export PATHmode=$1    # start or stop[ $# -ge 1 ] && shift   # $#:参数个数 遍历参数other_args="$*"   # uncommon, but needed when called from an RPM upgrade action# Expected: "--skip-networking --skip-grant-tables"# They are not checked here, intentionally, as it is the resposibility# of the "spec" file author to give correct arguments only.case `echo "testing\c"`,`echo -n testing` in*c*,-n*) echo_n=   echo_c=     ;;*c*,*)   echo_n=-n echo_c=     ;;*)       echo_n=   echo_c='\c' ;;
esacparse_server_arguments() {for arg docase "$arg" in--basedir=*)  basedir=`echo "$arg" | sed -e 's/^[^=]*=//'`bindir="$basedir/bin"if test -z "$datadir_set"; thendatadir="$basedir/data"fisbindir="$basedir/sbin"libexecdir="$basedir/libexec";;--datadir=*)  datadir=`echo "$arg" | sed -e 's/^[^=]*=//'`datadir_set=1;;--pid-file=*) mysqld_pid_file_path=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;--service-startup-timeout=*) service_startup_timeout=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;esacdone
}wait_for_pid () {verb="$1"           # created | removedpid="$2"            # process ID of the program operating on the pid-filepid_file_path="$3" # path to the PID file.i=0avoid_race_condition="by checking again"while test $i -ne $service_startup_timeout ; docase "$verb" in'created')# wait for a PID-file to pop into existence.test -s "$pid_file_path" && i='' && break;;'removed')# wait for this PID-file to disappeartest ! -s "$pid_file_path" && i='' && break;;*)echo "wait_for_pid () usage: wait_for_pid created|removed pid pid_file_path"exit 1;;esac# if server isn't running, then pid-file will never be updatedif test -n "$pid"; thenif kill -0 "$pid" 2>/dev/null; then:  # the server still runselse# The server may have exited between the last pid-file check and now.  if test -n "$avoid_race_condition"; thenavoid_race_condition=""continue  # Check again.fi# there's nothing that will affect the file.log_failure_msg "The server quit without updating PID file ($pid_file_path)."return 1  # not waiting any more.fifiecho $echo_n ".$echo_c"i=`expr $i + 1`sleep 1doneif test -z "$i" ; thenlog_success_msgreturn 0elselog_failure_msgreturn 1fi
}# Get arguments from the my.cnf file,
# the only group, which is read from now on is [mysqld]
if test -x "$bindir/my_print_defaults";  thenprint_defaults="$bindir/my_print_defaults"  #ok
else# Try to find basedir in /etc/my.cnfconf=/etc/my.cnfprint_defaults=if test -r $confthensubpat='^[^=]*basedir[^=]*=\(.*\)$'dirs=`sed -e "/$subpat/!d" -e 's//\1/' $conf`for d in $dirsdod=`echo $d | sed -e 's/[   ]//g'`if test -x "$d/bin/my_print_defaults"thenprint_defaults="$d/bin/my_print_defaults"breakfidonefi# Hope it's in the PATH ... but I doubt ittest -z "$print_defaults" && print_defaults="my_print_defaults"
fi#
# Read defaults file from 'basedir'.   If there is no defaults file there
# check if it's in the old (depricated) place (datadir) and read it from there
#extra_args=""
if test -r "$basedir/my.cnf"
thenextra_args="-e $basedir/my.cnf"
fiparse_server_arguments `$print_defaults $extra_args mysqld server mysql_server mysql.server`#
# Set pid file if not given 设置pid
#
if test -z "$mysqld_pid_file_path"  #如果mysqld_pid_file_path没设置
thenmysqld_pid_file_path=$datadir/`hostname`.pid
elsecase "$mysqld_pid_file_path" in/* ) ;;* )  mysqld_pid_file_path="$datadir/$mysqld_pid_file_path" ;;esac
ficase "$mode" in'start')# Start daemon# Safeguard (relative paths, core dumps..)cd $basedirecho $echo_n "Starting MySQL"if test -x $bindir/mysqld_safethen# Give extra arguments to mysqld with the my.cnf file. This script# may be overwritten at next upgrade.#--defaults-file要作为第一个参数出现$bindir/mysqld_safe --defaults-file="$datadir/my3307.cnf" --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null &wait_for_pid created "$!" "$mysqld_pid_file_path"; return_value=$?# Make lock for RedHat / SuSEif test -w "$lockdir"thentouch "$lock_file_path"fiexit $return_valueelselog_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"fi;;'stop')# Stop daemon. We use a signal here to avoid having to know the# root password.if test -s "$mysqld_pid_file_path"then# signal mysqld_safe that it needs to stoptouch "$mysqld_pid_file_path.shutdown"mysqld_pid=`cat "$mysqld_pid_file_path"`if (kill -0 $mysqld_pid 2>/dev/null)thenecho $echo_n "Shutting down MySQL"kill $mysqld_pid# mysqld should remove the pid file when it exits, so wait for it.wait_for_pid removed "$mysqld_pid" "$mysqld_pid_file_path"; return_value=$?elselog_failure_msg "MySQL server process #$mysqld_pid is not running!"rm "$mysqld_pid_file_path"fi# Delete lock for RedHat / SuSEif test -f "$lock_file_path"thenrm -f "$lock_file_path"fiexit $return_valueelselog_failure_msg "MySQL server PID file could not be found!"fi;;'restart')# Stop the service and regardless of whether it was# running or not, start it again.if $0 stop  $other_args; then$0 start $other_argselselog_failure_msg "Failed to stop running server, so refusing to try to start."exit 1fi;;'reload'|'force-reload')if test -s "$mysqld_pid_file_path" ; thenread mysqld_pid <  "$mysqld_pid_file_path"kill -HUP $mysqld_pid && log_success_msg "Reloading service MySQL" #平滑更新服务配置touch "$mysqld_pid_file_path"elselog_failure_msg "MySQL PID file could not be found!"exit 1fi;;'status')# First, check to see if pid file existsif test -s "$mysqld_pid_file_path" ; then read mysqld_pid < "$mysqld_pid_file_path"if kill -0 $mysqld_pid 2>/dev/null ; then log_success_msg "MySQL running ($mysqld_pid)"exit 0elselog_failure_msg "MySQL is not running, but PID file exists"exit 1fielse# Try to find appropriate mysqld processmysqld_pid=`pidof $libexecdir/mysqld`# test if multiple pids existpid_count=`echo $mysqld_pid | wc -w`if test $pid_count -gt 1 ; thenlog_failure_msg "Multiple MySQL running but PID file could not be found ($mysqld_pid)"exit 5elif test -z $mysqld_pid ; then if test -f "$lock_file_path" ; then log_failure_msg "MySQL is not running, but lock file ($lock_file_path) exists"exit 2fi log_failure_msg "MySQL is not running"exit 3elselog_failure_msg "MySQL is running but PID file could not be found"exit 4fifi;;*)# usagebasename=`basename "$0"`echo "Usage: $basename  {start|stop|restart|reload|force-reload|status}  [ MySQL server options ]"exit 1;;
esacexit 0

MySQL Deamon少量解读相关推荐

  1. mysql 启动 failed to start_Linux下启动MySQL提示“mysql deamon failed to start”错误的解决办法...

    有台Linux服务器,系统为CentOS系统. 描述: 网站突然连接不上数据库,于是朋友直接重启了一下服务器.进到cli模式下,执行 service myqsld start 发现还是提示" ...

  2. MySQL执行计划解读

    MySQL执行计划解读 http://www.cnblogs.com/ggjucheng/archive/2012/11/11/2765237.html MySQL执行计划解读 Explain语法 E ...

  3. mysql selecte_【mysql】MySQL eplain 完全解读

    EXPLAIN作为MySQL的性能分析神器,读懂其结果是很有必要的,然而我在各种搜索引擎上竟然找不到特别完整的解读.都是只有重点,没有细节(例如type的取值不全.Extra缺乏完整的介绍等). 所以 ...

  4. 【全网最全】 |MySQL EXPLAIN 完全解读

    TIPS 本文基于MySQL 8.0编写,理论支持MySQL 5.0及更高版本. EXPLAIN使用 explain可用来分析SQL的执行计划.格式如下: 1 2 3 4 5 6 7 8 9 10 1 ...

  5. MySQL源码解读之数据结构-LF_DYNARRAY

    MySQL的代码中实现了一个Lock Free的Hash结构,称作LF_Hash.MySQL的不少模块使用了LF_Hash,比如Metadata Lock就依赖于它.但由于使用的方法不正确,导致了bu ...

  6. 2022/12/17 mysql 索引基本原理解读

    1什么是索引 索引是帮助MySQL 高效获取数据的数据结构,通过使用索引可以在查询的过程中,使用优化隐藏器,提高系统的性能. https://www.cs.usfca.edu/~galles/visu ...

  7. MySQL SSL安全解读

    安全一直是不可不重视的问题.目前MySQL这方面应大方向上技术手段都具备.如:网络链接,权限控制,key秘钥认证,数据加密脱敏 等方式.综合考虑,虽然很多环境无法所有这些安全策略全部应用上,但在可控范 ...

  8. MySQL执行计划解读 转他人文章

    Explain语法 EXPLAIN SELECT -- 变体: 1. EXPLAIN EXTENDED SELECT -- 将执行计划"反编译"成SELECT语句,运行SHOW W ...

  9. 高质量解读《高性能mysql》——第3章服务器性能剖析

    前言: 高效读书,一张逻辑图带你读懂.读薄书中重点. 深入学习MySQL系列,解读的目的是为了把书读薄,抽出重点进行梳理.理解.运用.因大量文字很容易让人觉得枯燥无味,为此博主花费一定精力和时间整理输 ...

最新文章

  1. TFLearn 在给定模型精度时候提前终止训练
  2. 这个男人让你的爬虫开发效率提升8倍
  3. Boost:移动容器的测试程序
  4. iOS开发笔记[16/50]:Views
  5. java有几种变量_java有多少种变量?java类变量怎么使用?
  6. 未与信任 SQL Server 连接相关联
  7. TypeError: Unexpected keyword argument passed to optimizer: amsgrad原因及解决办法
  8. matplotlib可视化学习笔记
  9. Mnist数据集解析
  10. 使用C语言求一元二次方程的解
  11. SpringDataJPA之Specification复杂查询
  12. oracle dbms_lob trim,DBMS_LOB包基础应用
  13. Oracle 11G安装出错(Oracle执行先决条件检查失败)
  14. SparkSteaming运行流程分析以及CheckPoint操作
  15. 【小程序】使用wxParse解析html
  16. delphi如何将字符串复制到剪贴板上
  17. SQL Server 的几个故障
  18. 无法联网的情况下,dbeaver离线安装数据库驱动-clickhouse
  19. Gitlab 设置页面语言为简体中文
  20. 4 月答题挑战,得限量勋章赢现金 - 参与得“赏金”

热门文章

  1. 比较精确的计算农历节气的java源码
  2. Oracle数据库的一点
  3. mac常用基本操作笔记
  4. iOS开发之Your build settings specify a provisioning profile with the UUID “”, however, no such provisio
  5. java中二维数组Array
  6. 坐标系转换中位姿与位置
  7. 如何将苹果手机中的M4A音乐转换为MP3格式 1
  8. java程序求内切圆_JAVA求正方形边长,圆内切正方形,圆的直径为8,求正方形边长和面积!...
  9. C++数据结构问题:线性表的数据元素右移
  10. ajax java首字母检索_AJAX的拼音首字母查找对应中文的portlet