首页 > 代码库 > mysql,mairadb启动脚本
mysql,mairadb启动脚本
# mysql 启动脚本,一直使用mariadb,data目录一直不对,启动一直出错,自己编写的一个小脚本
# 适用于el6 systemd脚本 如果用ansible 使用service启动会报错,可以将service定义成脚本然后再使用ansible启动服务
#!/bin/bash
# MySQL daemon start/stop script.
# Name:mysql 启动脚本
# Version Number:1.0.5
# Type:检测服务状态
# 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 服务已启动"
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 启动成功 "
else
echo "mysql 启动失败 请查看日志: $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 $3}‘| head -1`
[ $MYSQL_MASTER_PID -eq 1 ] && continue || kill -9 $MYSQL_MASTER_PID
kill -9 $MYSQL_PID
[[ $RETVAL -eq 0 ]] && echo -e "mysql 已关闭\n" netstat -anput | grep mysql && rm -rf $mysqld_pid_file_path $lockfile || echo "mysql关闭失败,请查看日志 日志目录: $mysqld_error_file_path"
}
STATUSS(){
netstat -anput | grep 3306 | awk ‘{print $7}‘ | awk -F ‘/‘ ‘{print $1}‘ | head -1
RETVAL=$?
[ $RETVAL -eq 0 ] && echo "mysql 运行正常 pid值:`cat $mysqld_pid_file_path`" || echo "空,没有启动"
}
RELOADS(){
SERVERPD
MYSQL_PID=`cat $mysqld_pid_file_path`
kill -HUP $MYSQL_PID
[ $? -eq 0 ] && echo "重载配置成功" } || echo "重载配置失败"
}
SERVERPD(){
if [ ! -f $mysqld_pid_file_path ];then
echo "mysql服务没有启动"
exit 8
fi
}
case $1 in
start)
STARTS ;;
stop)
STOPS ;;
status)
STATUSS ;;
restart)
STOPS
STARTS ;;
reload)
RELOADS ;;
*)
echo "请使用: start | stop | status | restart | reload"
esac
本文出自 “xiong” 博客,请务必保留此出处http://xiong51.blog.51cto.com/5239058/1943517
mysql,mairadb启动脚本