# MySQL startup script, has been using the Mariadb,data directory has been wrong, startup has been wrong, a small script to write their own
# for El6 systemd scripts If you use the Ansible service startup error, you can define service as a script and then use Ansible to start services
#!/bin/bash
# MySQL Daemon start/stop script.
# Name:mysql Startup script
# Version number:1.0.5
# Type: Detect service Status
# Language:bash Shell
# date:2017-06-29
# Author:xiong
# Comments to support Chkconfig on RedHat Linux
# chkconfig:2345 64 36
# description:a very fast and reliable SQL database engine.
Set-e
Lockfile=${lockfile-/var/lock/subsys/mysql}
Basedirs=/usr/local/mysql
mysqld_pid_file_path=/data/mysql/' hostname '. PID
mysqld_error_file_path=/data/mysql/' hostname '. err
Starts () {
If [-F $mysqld _pid_file_path];then
echo "MySQL service started"
Exit 9
Fi
$basedirs/bin/mysqld_safe--datadir= '/data/mysql '--pid-file= $mysqld _pid_file_path &
Retval=$?
If [$RETVAL-eq 0];then
echo $ (pidof mysqld) > ${mysqld_pid_file_path}
Touch ${lockfile}
echo "MySQL startup succeeded"
Else
echo "MySQL startup failure please check log: $mysqld _error_file_path"
Fi
}
STOPS () {
Serverpd
Mysql_pid= ' Cat $mysqld _pid_file_path '
Mysql_master_pid= ' Ps-ef | grep $MYSQL _pid | Awk-f "" ' {print $} ' | Head-1 '
[$MYSQL _master_pid-eq 1] && Continue | | Kill-9 $MYSQL _master_pid
Kill-9 $MYSQL _pid
[[$RETVAL-eq 0]] && echo-e "MySQL is off \ n" netstat-anput | grep mysql && rm-rf $mysqld _pid_file_path $lockfile | | echo "MySQL shutdown failed, please view the log log directory: $mysqld _error_file_path"
}
Statuss () {
Netstat-anput | grep 3306 | awk ' {print $7} ' | Awk-f '/' {print $} ' | Head-1
Retval=$?
[$RETVAL-eq 0] && echo "MySQL run normal PID value: ' Cat $mysqld _pid_file_path '" | | echo "Empty, no Boot"
}
Reloads () {
Serverpd
Mysql_pid= ' Cat $mysqld _pid_file_path '
Kill-hup $MYSQL _pid
[$?-eq 0] && echo "Overload configuration Succeeded"} | | echo "Overloaded configuration Failed"
}
SERVERPD () {
if [!-F $mysqld _pid_file_path];then
echo "MySQL service does not start"
Exit 8
Fi
}
Case $ in
Start
starts;;
Stop
STOPS;;
Status
Statuss;;
Restart
STOPS
starts;;
Reload
reloads;;
*)
echo "Please use: Start | Stop | Status | Restart | Reload
Esac
This article is from the "Xiong" blog, make sure to keep this source http://xiong51.blog.51cto.com/5239058/1943517
MYSQL,MAIRADB Startup scripts