启动、关闭 MySQL服务 bat命令

 

:Main
@echo off
echo 获取Administrator权限
cacls.exe "%SystemDrive%\System Volume Information" >nul 2>nul
if %errorlevel%==0 goto Admin
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
echo Set RequestUAC = CreateObject^("Shell.Application"^)>"%temp%\getadmin.vbs"
echo RequestUAC.ShellExecute "%~s0","","","runas",1 >>"%temp%\getadmin.vbs"
echo WScript.Quit >>"%temp%\getadmin.vbs"
"%temp%\getadmin.vbs" /f
if exist "%temp%\getadmin.vbs" del /f /q "%temp%\getadmin.vbs"
exit 
:Admin
echo 成功获取Administrator权限
 
echo 检测MySQL状态
for /f "skip=3 tokens=4" %%i in ('sc query MySQL57') do set "zt=%%i" &goto :next
:next
if /i "%zt%"=="RUNNING" (
    echo MySQL服务运行中
    echo 关闭MySQL
    net stop "MySQL57"
    pause
) else (
    echo MySQL服务处于停止状态
    echo 启动MySQL
    net start "MySQL57"
    pause
)