创建 MySQL 多实例的启动文件

来源:转载


[[email protected] ~]# vim /data/3306/mysql
#!/bin/bash
port=3306
mysql_user="root"# 根据实际修改mysql_pwd="pzk123" # 根据实际修改CmdPath="/usr/local/mysql/bin"mysql_sock="/data/${port}/mysql.sock"# startup functionfunction_start_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "Starting MySQL.../n"/bin/sh ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf 2>&1 > /dev/null &elseprintf "MySQL is running.../n"exitfi}# stop functionfunction_stop_mysql(){if [ ! -e "$mysql_sock" ];thenprintf "MySQL is stopped.../n"exitelseprintf "Stoping MySQL.../n"${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /data/${port}/mysql.sock shutdownfi}# restart functionfunction_restart_mysql(){printf "Restarting MySQL.../n"function_stop_mysqlsleep 2function_start_mysql}case $1 instart)function_start_mysql;;stop)function_stop_mysql;;restart)function_restart_mysql;;*)printf "Usage: /data/${port}/mysql {start|stop|restart}/n"esac

[[email protected]~]#vim/data/3307/mysql
#!/bin/bash
port=3307
mysql_user="root"#根据实际修改mysql_pwd="pzk123"#根据实际修改CmdPath="/usr/local/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"

#startupfunction
function_start_mysql()
{
if[!-e"$mysql_sock"];then
printf"StartingMySQL.../n"
/bin/sh${CmdPath}/mysqld_safe--defaults-file=/data/${port}/my.cnf2>&1>/dev/null&
else
printf"MySQLisrunning.../n"
exit
fi
}

#stopfunction
function_stop_mysql()
{
if[!-e"$mysql_sock"];then
printf"MySQLisstopped.../n"
exit
else
printf"StopingMySQL.../n"
${CmdPath}/mysqladmin-u${mysql_user}-p${mysql_pwd}-S/data/${port}/mysql.sockshutdown
fi
}

#restartfunction
function_restart_mysql()
{
printf"RestartingMySQL.../n"
function_stop_mysql
sleep2
function_start_mysql
}

case$1in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf"Usage:/data/${port}/mysql{start|stop|restart}/n"
esac


分享给朋友:
您可能感兴趣的文章:
随机阅读: