An experienced person will show you how to develop a professional and standardized MySQL startup script

An experienced person will show you how to develop a professional and standardized MySQL startup script

Every qualified Linux operation and maintenance personnel should be proficient or proficient in Shell script programming, because Shell scripting language is almost the simplest language of all programming languages. If Shell script is not good, it means that the operation and maintenance road may end before it even begins. ——Old boy teacher

#!/bin/bash
# chkconfig: 2345 64 36 #Configure system auto-start# 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
##############################################################
#Introduce the system function library. /etc/init.d/functions

#Basic path definition 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'

#Success prompt function log_success_msg(){
  #action is a special prompt function, $@ is all parameters.
  action "SUCCESS! $@" /bin/true
}
#Failure prompt function log_failure_msg(){
  action "ERROR! $@" /bin/false
 }
 
#mysql start function start(){
  echo $"Starting MySQL"
  #Test whether mysqld_safe is executable if test -x $bindir/mysqld_safe
  then
    #Background execution starts mysql command $bindir/mysqld_safe &>/dev/null &
    #Get the return value retval=$?
    # Check if the return value is 0
    if [ $retval -eq 0 ]
    then
      #Call the success prompt function.
      log_success_msg "mysql Startup"
      if test -w "$lockdir" #Judge whether the lock directory is writable.
      then
        touch "$lock_file_path" #Create a lock file.
      fi
      return $retval #Giving a return value is a professional gesture.
    else
      log_failure_msg "MySQL Startup" #Prompt of failed function call.
      return $retval
    fi
  else
    log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
  fi
}
#Stop the MySQL function.
stop(){
  #Judge whether the mysql pid file size is 0.
  if test -s "$mysqld_pid_file_path"
  then
    #Read pidfile
    mysqld_pid=`cat "$mysqld_pid_file_path"`
    #Judge whether the process corresponding to mysql pid exists.
    if (kill -0 $mysqld_pid 2>/dev/null)
    then
      echo $"Shutting down MySQL"
      kill $mysqld_pid #Stop the MySQL command.
      retval=$?
      if [ $retval -eq 0 ]
      then
        log_success_msg "MySQL Stop" #Call the stop success function.
        if test -f "$lock_file_path"
        then
          rm -f "$lock_file_path" #Delete the lock file.
        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 does not exist!"
  fi
}
#Receive the passed parameters and execute the corresponding function.
case "$1" in
  start)
    start
    retval=$?
    ;;
  stop)
    stop
    retval=$?
    ;;
  restart)
    stop
    sleep 2 #This is very important, take a rest.
    start
    retval=$?
    ;;
  *)
    echo $"Usage:$0 {start|stop|restart}"
    exit 2
esac
exit $retval #After executing the script, it is more professional to have a return value.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Summary of MySQL usage specifications
  • Super detailed MySQL usage specification sharing
  • Summary of MySQL database usage specifications
  • Summary of MySQL development standards and usage skills
  • MySQL database development specifications [recommended]
  • MySQL database naming standards and conventions
  • Detailed explanation of Mysql table creation and index usage specifications
  • MYSQL database naming and design specifications
  • Professional MySQL development design specifications and SQL writing specifications

<<:  jQuery implements nested tab function

>>:  Use of Linux relative and absolute paths

Recommend

Instructions for using the --rm option of docker run

When the Docker container exits, the file system ...

How MySQL supports billions of traffic

Table of contents 1 Master-slave read-write separ...

Hbase Getting Started

1. HBase Overview 1.1 What is HBase HBase is a No...

How to quickly modify the table structure of MySQL table

Quickly modify the table structure of a MySQL tab...

Form submission page refresh does not jump

1. Design source code Copy code The code is as fol...

How to check and organize website files using Dreamweaver8

What is the purpose of creating your own website u...

Detailed explanation of the relationship between Linux and GNU systems

Table of contents What is the Linux system that w...

How to use sed command to efficiently delete specific lines of a file

Preface Normally, if we want to delete certain li...

Implement QR code scanning function through Vue

hint This plug-in can only be accessed under the ...

React Fragment Introduction and Detailed Usage

Table of contents Preface Motivation for Fragment...

Methods and steps for deploying go projects based on Docker images

Dependence on knowledge Go cross-compilation basi...

Specific usage of CSS compound selectors

Intersection Selector The intersection selector i...

Implementation code for partial refresh of HTML page

Event response refresh: refresh only when request...