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

In-depth analysis of the Tomcat server of Centos 7 system

Table of contents 1. The origin of tomcat 1. Tomc...

Ways to improve MongoDB performance

MongoDB is a high-performance database, but in th...

React's reconciliation algorithm Diffing algorithm strategy detailed explanation

Table of contents Algorithmic Strategy Single-nod...

Detailed explanation of ES6 Promise usage

Table of contents What is a Promise? Usage of rej...

Vue+echarts realizes progress bar histogram

This article shares the specific code of vue+echa...

10 Deadly Semantic Mistakes in Web Typography

<br />This is from the content of Web front-...

JavaScript canvas to achieve colorful clock effect

Use canvas to write a colorful clock! 1. Title (1...

Docker image access to local elasticsearch port operation

Using the image service deployed by docker stack,...

mysql workbench installation and configuration tutorial under centOS

This article shares the MySQL Workbench installat...

JS implements request dispatcher

Table of contents Abstraction and reuse Serial Se...

Use of Linux read command

1. Command Introduction The read command is a bui...

MySQL database master-slave configuration tutorial under Windows

The detailed process of configuring the MySQL dat...