搜索版
@echo off & setlocal:loopset /p answer=Do you want to continue (y/n)echo You chose: %answer%if /i {%answer%}=={y} goto :mysqlNameif /i {%answer%}=={n} goto :noecho.echo.echo Invalid selection, try again&&goto :mysqlNamerem 选择mysqld.exe 的新名字:mysqlNameecho ================ 选择mysql版本 ===============echo -------------------------------------echo 1. mysqld56echo 2. mysqld57echo 3. mysqld80echo ==========PRESS '0' TO QUIT==========echo.set inputn=set /p inputn=Please select a number:if /i '%inputn%'=='1' goto mysqld56sif /i '%inputn%'=='2' goto mysqld57sif /i '%inputn%'=='3' goto mysqld80sif /i '%inputn%'=='0' goto endecho.echo.rem 输入错误跳回 inputecho wrong number, try it again&&goto :loop:mysqld56sset setMysql=mysqld56goto search:mysqld57sset setMysql=mysqld57goto search:mysqld80sset setMysql=mysqld80goto searchrem 指定待搜索的文件:searchecho 正在搜索,请稍候...for %%a in (C D E F G H I J K L M N O P Q R S T U V W X Y Z) do ( if exist %%a:\ ( for /f "delims=" %%b in ('dir /a-d /s /b "%%a:\*%setMysql%.exe" 2^>nul') do ( if /i "%%~nxb" equ "%setMysql%.exe" ( echo 搜索结束,文件路径为:%%b for %%a in (%%b) do ( echo %%~nxa set fileName=%%~nxa ) set currentDirss=%%b goto searchOk ) ) )):searchOkset isNull=%currentDirss%if "%isNull%"=="" ( echo 搜索的文件不存在 goto end) else ( goto yes):yesecho ================ 选择mysql功能 ===============echo.set currentDir=%currentDirss:~0,-13%set drives=%currentDirss:~0,2%SET dataFolder=%currentDir:~0,-3%dataecho 查看mysql路径%currentDir%echo 启动的文件名:%fileName%echo cd 路径:%currentDir% %drives%echo data文件夹路径:%dataFolder%echo.echo -------------------------------------echo 1. 启动mysql 1echo 2. 进入mysql 2echo 3. 结束进程mysql 3echo ==========PRESS '0' TO QUIT==========echo.echo.set input=set /p input=Please select a number:if /i '%input%'=='1' goto startMysqlif /i '%input%'=='2' goto goMysqlif /i '%input%'=='3' goto killMysqlif /i '%input%'=='0' goto endecho.echo.rem 输入错误跳回 inputecho wrong number, try it again&&goto :mysqlName:startMysqlecho.call taskkill /f /im %fileName%if %errorlevel% == 0 ( echo 杀死%setMysql%进程成功) else ( echo 杀死%setMysql%进程失败)echo.echo Starting %setMysql% ...if exist %dataFolder% ( rem 目录data已存在,无需创建 echo 目录%dataFolder%目录已存在,无需创建! goto startMysqlSucceed ) else ( rem 创建data目录,使用复制方法 echo %dataFolder%目录不存在,已创建该目录! md %dataFolder% rem 睡3秒创建文件夹 timeout /T 3 /NOBREAK rem 睡醒了 cd /d %currentDir% call %setMysql% --initialize-insecure --console && (goto startMysqlSucceed) || goto startMysqlFailed ):startMysqlSucceedrem 睡三秒timeout /T 3 /NOBREAKcd /d %currentDir%echo 当前路径 %cd%start %fileName%echo 启动%setMysql%成功echo.echo.goto loop2:startMysqlFailedecho 初始化失败 删除文件夹rd /s /q %dataFolder%goto end:goMysqlecho.echo.cd /d %currentDir%echo 当前路径 %cd%call mysqlif %errorlevel% == 0 ( echo 启动%setMysql%命令行成功) else ( echo 启动%setMysql%命令行失败)echo.echo.goto loop2:killMysqlecho.echo 当前路径 %cd%echo.call taskkill /f /im %fileName%if %errorlevel% == 0 ( echo 杀死%setMysql%进程成功) else ( echo 杀死%setMysql%进程失败)echo.echo.goto loop2:loop2echo ================ mysql ===============echo -------------------------------------echo 1. 选择mysql版本 1echo 2. 选择mysql功能 2echo ==========PRESS '0' TO QUIT==========echo.set input=set /p input=Please select a number:if /i '%input%'=='1' goto mysqlNameif /i '%input%'=='2' goto yesif /i '%input%'=='0' goto endecho.echo.rem 输入错误跳回 inputecho wrong number, try it again&&goto :loopgoto end:no:endecho Good-bye!rem pause endlocal & @echo on
指定路径版
@echo off & setlocal:loopset /p answer=Do you want to continue (y/n)echo You chose: %answer%if /i {%answer%}=={y} goto :mysqlNameif /i {%answer%}=={n} goto :noecho.echo.echo Invalid selection, try again&&goto :mysqlNamerem 选择mysqld.exe 的新名字:mysqlNameecho ================ 选择mysql版本 ===============echo -------------------------------------echo 1. mysqld56echo 2. mysqld57echo 3. mysqld80echo ==========PRESS '0' TO QUIT==========echo.set inputn=set /p inputn=Please select a number:if /i '%inputn%'=='1' goto mysqld56sif /i '%inputn%'=='2' goto mysqld57sif /i '%inputn%'=='3' goto mysqld80sif /i '%inputn%'=='0' goto endecho.echo.rem 输入错误跳回 inputecho wrong number, try it again&&goto :loop:mysqld56sset setMysql=mysqld56set fileName=%setMysql%.exeset currentDirss=D:\app\S_mysql\mysql-5.6.23-winx64\bin\%fileName%goto yes:mysqld57sset setMysql=mysqld57set fileName=%setMysql%.exeset currentDirss=D:\app\S_mysql\mysql-5.7.31-winx64\bin\%fileName%goto yes:mysqld80sset setMysql=mysqld80set fileName=%setMysql%.exeset currentDirss=D:\app\S_mysql\mysql-8.0.21-3336\bin\%fileName%goto yes:yesecho ================ 选择mysql功能 ===============echo.set currentDir=%currentDirss:~0,-13%set drives=%currentDirss:~0,2%SET dataFolder=%currentDir:~0,-3%dataecho 查看mysql路径%currentDir%echo 启动的文件名:%fileName%echo cd 路径:%currentDir% %drives%echo data文件夹路径:%dataFolder%echo.echo -------------------------------------echo 1. 启动mysql 1echo 2. 进入mysql 2echo 3. 结束进程mysql 3echo ==========PRESS '0' TO QUIT==========echo.echo.set input=set /p input=Please select a number:if /i '%input%'=='1' goto startMysqlif /i '%input%'=='2' goto goMysqlif /i '%input%'=='3' goto killMysqlif /i '%input%'=='0' goto endecho.echo.rem 输入错误跳回 inputecho wrong number, try it again&&goto :mysqlName:startMysqlecho.call taskkill /f /im %fileName%if %errorlevel% == 0 ( echo 杀死%setMysql%进程成功) else ( echo 杀死%setMysql%进程失败)echo.echo Starting %setMysql% ...if exist %dataFolder% ( rem 目录data已存在,无需创建 echo 目录%dataFolder%目录已存在,无需创建! goto startMysqlSucceed ) else ( rem 创建data目录,使用复制方法 echo %dataFolder%目录不存在,已创建该目录! md %dataFolder% rem 睡3秒创建文件夹 timeout /T 3 /NOBREAK rem 睡醒了 cd /d %currentDir% call %setMysql% --initialize-insecure --console && (goto startMysqlSucceed) || goto startMysqlFailed ):startMysqlSucceedrem 睡三秒timeout /T 3 /NOBREAKcd /d %currentDir%echo 当前路径 %cd%start %fileName%echo 启动%setMysql%成功echo.echo.goto loop2:startMysqlFailedecho 初始化失败 删除文件夹rd /s /q %dataFolder%goto end:goMysqlecho.echo.cd /d %currentDir%echo 当前路径 %cd%call mysqlif %errorlevel% == 0 ( echo 启动%setMysql%命令行成功) else ( echo 启动%setMysql%命令行失败)echo.echo.goto loop2:killMysqlecho.echo 当前路径 %cd%echo.call taskkill /f /im %fileName%if %errorlevel% == 0 ( echo 杀死%setMysql%进程成功) else ( echo 杀死%setMysql%进程失败)echo.echo.goto loop2:loop2echo ================ mysql ===============echo -------------------------------------echo 1. 选择mysql版本 1echo 2. 选择mysql功能 2echo ==========PRESS '0' TO QUIT==========echo.set input=set /p input=Please select a number:if /i '%input%'=='1' goto mysqlNameif /i '%input%'=='2' goto yesif /i '%input%'=='0' goto endecho.echo.rem 输入错误跳回 inputecho wrong number, try it again&&goto :loopgoto end:no:endecho Good-bye!rem pause endlocal & @echo on