Shell script: simple script for MySQL to start
It is recommended to compile a simple MySQL STARTUP script using shell scripts, and to practice the usage of variables, functions, and case statements;
[Root @ localhost baby] # cat mysql_function.sh
#! /Bin/bash
./Etc/init. d/functions
Path =/usr/local/mysql/bin/
Function usage (){
Echo "$0 {start | stop | restart }"
Exit 1
}
[$ #-Ne 1] & usage
Function_mysql_start (){
$ Path/mysqld_safe -- user = mysql &>/dev/null &
If [$? -Eq 0]
Then
Sleep 5
Action "start mysql"/bin/true
Else
Action "start mysql"/bin/false
Fi
}
Function_mysql_stop (){
$ Path/mysqladmin-uroot shutdown &>/dev/null
If [$? -Eq 0]
Then
Action "stop mysql"/bin/true
Else
Action "stop mysql"/bin/false
Fi
}
Function_mysql_restart (){
Function_mysql_stop
Sleep 3
Function_mysql_start
}
Case $1 in
Start)
Function_mysql_start
;;
Stop)
Function_mysql_stop
;;
Restart)
Function_mysql_restart
;;
*)
Printf "Usage: $0 {start | stop | restart} \ n"
Esac
Shows the execution result:
This article permanently updates the link address: