@echo off
for /f "skip=3 tokens=4" %%i in ('sc query mysql') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
echo 已经发现该服务在运行,正在已经关闭服务
net stop mysql
) else (
echo 该服务现在处理停止状态,正在现在开启服务
net start mysql
)
exit
pause
#!/bin/sh
mysql_port=3306
mysql_username="root"
mysql_password=""
function_start_mysql()
{
printf "Starting MySQL...n"
/bin/sh /data/mysql/bin/mysqld_safe --defaults-file=/data/mysql/${mysql_port}/my.cnf 2>&1 > /dev/null &
}
function_stop_mysql()
{
printf "Stoping MySQL...n"
/data/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/mysql/mysql.sock shutdown
}
function_restart_mysql()
{
printf "Restarting MySQL...n"
function_stop_mysql
sleep 5
function_start_mysql
}
function_kill_mysql()
{
kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port}
|
linuxjishu/13830.html target=_blank class=infotextkey>awk '{printf $2}')
kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port}
| awk '{printf $2}')
}
if [ "$1" = "start" ]; then
function_start_mysql
elif [ "$1" = "stop" ]; then
function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
printf "Usage: /data/mysql/${mysql_port}/mysql
{start|stop|restart|kill}n"
fi