#!/bin/bash
#注:多实例DB数据,sock目录要统一
#每个实例要建有shutdown权限mt_user用户.
myd='/usr/local/mysql/bin/mysqld'
myadmin='/usr/local/mysql/bin/mysqladmin'
m_user='mt_user'
m_password='abcd123'
port=`netstat -tnlp|grep mysql|awk -F':' '{print $4}'|grep "$2"`
if [ "$1" == "start" ];then
{
if [ -z "$port" ];then
"$myd" --defaults-file=/data/mysql/mysql"$2"/my.cnf &
elif [ $2 -eq "$port" ];then
printf 'Sorry that the port is occupied'"%s %s
"
exit
fi
}
elif [ "$1" == "restart" ];then
"$myadmin" -u"$m_user" -p"$m_password" -S /tmp/mysql"$2".sock shutdown
sleep 2
"$myd" --defaults-file=/data/mysql/mysql"$2"/my.cnf &
elif [ "$1" == "stop" ];then
"$myadmin" -u"$m_user" -p"$m_password" -S /tmp/mysql"$2".sock shutdown
else
printf 'Please enter start+port or restart+port or stop+port'"%s %s
"
fi
停止DB
sh mt_mysql.sh stop 3306
启动DB
sh mt_mysql.sh start 3306
重启DB
sh mt_mysql.sh restart 3306
#@_@ 欢迎交流!联系人 广西宾阳 阿桂 qq149951292