.bat 批处理 - 查看 MySQL 状态然后启动或关闭
我的 MySQL 服务名为 MySQL80,具体的以实际为准:
@echo off
setlocal:check_status
cls
sc query MySQL80 | find "RUNNING" > nul 2>&1
if %errorlevel%==0 (echo Current status of MySQL service: Running
) else (echo Current status of MySQL service: Stopped
):menu
echo Choose an option:
echo 1. Start MySQL service
echo 2. Stop MySQL service
echo 3. Exitset /p choice=Enter an option:if "%choice%"=="1" (net start MySQL80echo MySQL service has been started.pausegoto check_status
)if "%choice%"=="2" (net stop MySQL80echo MySQL service has been stopped.pausegoto check_status
)if "%choice%"=="3" (echo Exiting the script.exit /b 0
)echo Invalid option. Please select again.
pause
goto menu