博客
关于我
MySQL单实例或多实例启动脚本
阅读量:789 次
发布时间:2023-02-12

本文共 860 字,大约阅读时间需要 2 分钟。

以下是优化后的文章内容:


MySQL数据库自动启动和停止脚本

脚本简介

#!/bin/bash

脚本依赖

. /etc/init.d/functions

脚本参数

user=rootpass=888888path=/application/mysql/bin

功能说明

function usage(){    echo "Usage:$0 {start|stop|restart|}"    exit 1}

脚本逻辑

function start_db(){    $path/mysqld_safe --user=$user > /dev/null &    if [ $? -eq 0 ]; then        echo "starting MySQL..." true    else        echo "starting MySQL..." false    fi}function stop_db(){    $path/mysqladmin -u$user -p$pass shutdown > /dev/null    if [ $? -eq 0 ]; then        echo "stoping MySQL..." true    else        echo "stop MySQL..." false    fi}

脚本执行规则

if [ "$1" == "start" ]; then    start_dbelif [ "$1" == "stop" ]; then    stop_dbelif [ "$1" == "restart" ]; then    stop_db    sleep 3    start_dbelse    usagefi

使用说明

# 启动 MySQL./mysqld01.sh start# 停止 MySQL./mysqld01.sh stop# 重启 MySQL./mysqld01.sh restart

本文内容来源于:51CTO技术博客

转载地址:http://pmbfk.baihongyu.com/

你可能感兴趣的文章