搜索版
@echo off & setlocal
:loop
set /p answer=Do you want to continue (y/n)
echo You chose: %answer%
if /i {%answer%}=={y} goto :mysqlName
if /i {%answer%}=={n} goto :no
echo.
echo.
echo Invalid selection, try again&&goto :mysqlName
rem 选择mysqld.exe 的新名字
:mysqlName
echo ================ 选择mysql版本 ===============
echo -------------------------------------
echo 1. mysqld56
echo 2. mysqld57
echo 3. mysqld80
echo ==========PRESS '0' TO QUIT==========
echo.
set inputn=
set /p inputn=Please select a number:
if /i '%inputn%'=='1' goto mysqld56s
if /i '%inputn%'=='2' goto mysqld57s
if /i '%inputn%'=='3' goto mysqld80s
if /i '%inputn%'=='0' goto end
echo.
echo.
rem 输入错误跳回 input
echo wrong number, try it again&&goto :loop
:mysqld56s
set setMysql=mysqld56
goto search
:mysqld57s
set setMysql=mysqld57
goto search
:mysqld80s
set setMysql=mysqld80
goto search
rem 指定待搜索的文件
:search
echo 正在搜索,请稍候...
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
)
)
)
)
:searchOk
set isNull=%currentDirss%
if "%isNull%"=="" (
echo 搜索的文件不存在
goto end
) else (
goto yes
)
:yes
echo ================ 选择mysql功能 ===============
echo.
set currentDir=%currentDirss:~0,-13%
set drives=%currentDirss:~0,2%
SET dataFolder=%currentDir:~0,-3%data
echo 查看mysql路径%currentDir%
echo 启动的文件名:%fileName%
echo cd 路径:%currentDir% %drives%
echo data文件夹路径:%dataFolder%
echo.
echo -------------------------------------
echo 1. 启动mysql 1
echo 2. 进入mysql 2
echo 3. 结束进程mysql 3
echo ==========PRESS '0' TO QUIT==========
echo.
echo.
set input=
set /p input=Please select a number:
if /i '%input%'=='1' goto startMysql
if /i '%input%'=='2' goto goMysql
if /i '%input%'=='3' goto killMysql
if /i '%input%'=='0' goto end
echo.
echo.
rem 输入错误跳回 input
echo wrong number, try it again&&goto :mysqlName
:startMysql
echo.
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
)
:startMysqlSucceed
rem 睡三秒
timeout /T 3 /NOBREAK
cd /d %currentDir%
echo 当前路径 %cd%
start %fileName%
echo 启动%setMysql%成功
echo.
echo.
goto loop2
:startMysqlFailed
echo 初始化失败 删除文件夹
rd /s /q %dataFolder%
goto end
:goMysql
echo.
echo.
cd /d %currentDir%
echo 当前路径 %cd%
call mysql
if %errorlevel% == 0 (
echo 启动%setMysql%命令行成功
) else (
echo 启动%setMysql%命令行失败
)
echo.
echo.
goto loop2
:killMysql
echo.
echo 当前路径 %cd%
echo.
call taskkill /f /im %fileName%
if %errorlevel% == 0 (
echo 杀死%setMysql%进程成功
) else (
echo 杀死%setMysql%进程失败
)
echo.
echo.
goto loop2
:loop2
echo ================ mysql ===============
echo -------------------------------------
echo 1. 选择mysql版本 1
echo 2. 选择mysql功能 2
echo ==========PRESS '0' TO QUIT==========
echo.
set input=
set /p input=Please select a number:
if /i '%input%'=='1' goto mysqlName
if /i '%input%'=='2' goto yes
if /i '%input%'=='0' goto end
echo.
echo.
rem 输入错误跳回 input
echo wrong number, try it again&&goto :loop
goto end
:no
:end
echo Good-bye!
rem pause
endlocal & @echo on
指定路径版
@echo off & setlocal
:loop
set /p answer=Do you want to continue (y/n)
echo You chose: %answer%
if /i {%answer%}=={y} goto :mysqlName
if /i {%answer%}=={n} goto :no
echo.
echo.
echo Invalid selection, try again&&goto :mysqlName
rem 选择mysqld.exe 的新名字
:mysqlName
echo ================ 选择mysql版本 ===============
echo -------------------------------------
echo 1. mysqld56
echo 2. mysqld57
echo 3. mysqld80
echo ==========PRESS '0' TO QUIT==========
echo.
set inputn=
set /p inputn=Please select a number:
if /i '%inputn%'=='1' goto mysqld56s
if /i '%inputn%'=='2' goto mysqld57s
if /i '%inputn%'=='3' goto mysqld80s
if /i '%inputn%'=='0' goto end
echo.
echo.
rem 输入错误跳回 input
echo wrong number, try it again&&goto :loop
:mysqld56s
set setMysql=mysqld56
set fileName=%setMysql%.exe
set currentDirss=D:\app\S_mysql\mysql-5.6.23-winx64\bin\%fileName%
goto yes
:mysqld57s
set setMysql=mysqld57
set fileName=%setMysql%.exe
set currentDirss=D:\app\S_mysql\mysql-5.7.31-winx64\bin\%fileName%
goto yes
:mysqld80s
set setMysql=mysqld80
set fileName=%setMysql%.exe
set currentDirss=D:\app\S_mysql\mysql-8.0.21-3336\bin\%fileName%
goto yes
:yes
echo ================ 选择mysql功能 ===============
echo.
set currentDir=%currentDirss:~0,-13%
set drives=%currentDirss:~0,2%
SET dataFolder=%currentDir:~0,-3%data
echo 查看mysql路径%currentDir%
echo 启动的文件名:%fileName%
echo cd 路径:%currentDir% %drives%
echo data文件夹路径:%dataFolder%
echo.
echo -------------------------------------
echo 1. 启动mysql 1
echo 2. 进入mysql 2
echo 3. 结束进程mysql 3
echo ==========PRESS '0' TO QUIT==========
echo.
echo.
set input=
set /p input=Please select a number:
if /i '%input%'=='1' goto startMysql
if /i '%input%'=='2' goto goMysql
if /i '%input%'=='3' goto killMysql
if /i '%input%'=='0' goto end
echo.
echo.
rem 输入错误跳回 input
echo wrong number, try it again&&goto :mysqlName
:startMysql
echo.
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
)
:startMysqlSucceed
rem 睡三秒
timeout /T 3 /NOBREAK
cd /d %currentDir%
echo 当前路径 %cd%
start %fileName%
echo 启动%setMysql%成功
echo.
echo.
goto loop2
:startMysqlFailed
echo 初始化失败 删除文件夹
rd /s /q %dataFolder%
goto end
:goMysql
echo.
echo.
cd /d %currentDir%
echo 当前路径 %cd%
call mysql
if %errorlevel% == 0 (
echo 启动%setMysql%命令行成功
) else (
echo 启动%setMysql%命令行失败
)
echo.
echo.
goto loop2
:killMysql
echo.
echo 当前路径 %cd%
echo.
call taskkill /f /im %fileName%
if %errorlevel% == 0 (
echo 杀死%setMysql%进程成功
) else (
echo 杀死%setMysql%进程失败
)
echo.
echo.
goto loop2
:loop2
echo ================ mysql ===============
echo -------------------------------------
echo 1. 选择mysql版本 1
echo 2. 选择mysql功能 2
echo ==========PRESS '0' TO QUIT==========
echo.
set input=
set /p input=Please select a number:
if /i '%input%'=='1' goto mysqlName
if /i '%input%'=='2' goto yes
if /i '%input%'=='0' goto end
echo.
echo.
rem 输入错误跳回 input
echo wrong number, try it again&&goto :loop
goto end
:no
:end
echo Good-bye!
rem pause
endlocal & @echo on