当前位置:Gxlcms > 数据库问题 > mysql,mairadb启动脚本

mysql,mairadb启动脚本

时间:2021-07-01 10:21:17 帮助过:3人阅读

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启动脚本

标签:mysql   脚本   

人气教程排行