搜索版

  1. @echo off & setlocal
  2. :loop
  3. set /p answer=Do you want to continue (y/n)
  4. echo You chose: %answer%
  5. if /i {%answer%}=={y} goto :mysqlName
  6. if /i {%answer%}=={n} goto :no
  7. echo.
  8. echo.
  9. echo Invalid selection, try again&&goto :mysqlName
  10. rem 选择mysqld.exe 的新名字
  11. :mysqlName
  12. echo ================ 选择mysql版本 ===============
  13. echo -------------------------------------
  14. echo 1. mysqld56
  15. echo 2. mysqld57
  16. echo 3. mysqld80
  17. echo ==========PRESS '0' TO QUIT==========
  18. echo.
  19. set inputn=
  20. set /p inputn=Please select a number:
  21. if /i '%inputn%'=='1' goto mysqld56s
  22. if /i '%inputn%'=='2' goto mysqld57s
  23. if /i '%inputn%'=='3' goto mysqld80s
  24. if /i '%inputn%'=='0' goto end
  25. echo.
  26. echo.
  27. rem 输入错误跳回 input
  28. echo wrong number, try it again&&goto :loop
  29. :mysqld56s
  30. set setMysql=mysqld56
  31. goto search
  32. :mysqld57s
  33. set setMysql=mysqld57
  34. goto search
  35. :mysqld80s
  36. set setMysql=mysqld80
  37. goto search
  38. rem 指定待搜索的文件
  39. :search
  40. echo 正在搜索,请稍候...
  41. 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 (
  42. if exist %%a:\ (
  43. for /f "delims=" %%b in ('dir /a-d /s /b "%%a:\*%setMysql%.exe" 2^>nul') do (
  44. if /i "%%~nxb" equ "%setMysql%.exe" (
  45. echo 搜索结束,文件路径为:%%b
  46. for %%a in (%%b) do (
  47. echo %%~nxa
  48. set fileName=%%~nxa
  49. )
  50. set currentDirss=%%b
  51. goto searchOk
  52. )
  53. )
  54. )
  55. )
  56. :searchOk
  57. set isNull=%currentDirss%
  58. if "%isNull%"=="" (
  59. echo 搜索的文件不存在
  60. goto end
  61. ) else (
  62. goto yes
  63. )
  64. :yes
  65. echo ================ 选择mysql功能 ===============
  66. echo.
  67. set currentDir=%currentDirss:~0,-13%
  68. set drives=%currentDirss:~0,2%
  69. SET dataFolder=%currentDir:~0,-3%data
  70. echo 查看mysql路径%currentDir%
  71. echo 启动的文件名:%fileName%
  72. echo cd 路径:%currentDir% %drives%
  73. echo data文件夹路径:%dataFolder%
  74. echo.
  75. echo -------------------------------------
  76. echo 1. 启动mysql 1
  77. echo 2. 进入mysql 2
  78. echo 3. 结束进程mysql 3
  79. echo ==========PRESS '0' TO QUIT==========
  80. echo.
  81. echo.
  82. set input=
  83. set /p input=Please select a number:
  84. if /i '%input%'=='1' goto startMysql
  85. if /i '%input%'=='2' goto goMysql
  86. if /i '%input%'=='3' goto killMysql
  87. if /i '%input%'=='0' goto end
  88. echo.
  89. echo.
  90. rem 输入错误跳回 input
  91. echo wrong number, try it again&&goto :mysqlName
  92. :startMysql
  93. echo.
  94. call taskkill /f /im %fileName%
  95. if %errorlevel% == 0 (
  96.  echo 杀死%setMysql%进程成功
  97. ) else (
  98.  echo 杀死%setMysql%进程失败
  99. )
  100. echo.
  101. echo Starting %setMysql% ...
  102. if exist %dataFolder% (
  103. rem 目录data已存在,无需创建
  104. echo 目录%dataFolder%目录已存在,无需创建!
  105. goto startMysqlSucceed
  106. ) else (
  107. rem 创建data目录,使用复制方法
  108. echo %dataFolder%目录不存在,已创建该目录!
  109. md %dataFolder%
  110. rem 3秒创建文件夹
  111. timeout /T 3 /NOBREAK
  112. rem 睡醒了
  113. cd /d %currentDir%
  114. call %setMysql% --initialize-insecure --console && (goto startMysqlSucceed) || goto startMysqlFailed
  115. )
  116. :startMysqlSucceed
  117. rem 睡三秒
  118. timeout /T 3 /NOBREAK
  119. cd /d %currentDir%
  120. echo 当前路径 %cd%
  121. start %fileName%
  122. echo 启动%setMysql%成功
  123. echo.
  124. echo.
  125. goto loop2
  126. :startMysqlFailed
  127. echo 初始化失败 删除文件夹
  128. rd /s /q %dataFolder%
  129. goto end
  130. :goMysql
  131. echo.
  132. echo.
  133. cd /d %currentDir%
  134. echo 当前路径 %cd%
  135. call mysql
  136. if %errorlevel% == 0 (
  137.  echo 启动%setMysql%命令行成功
  138. ) else (
  139.  echo 启动%setMysql%命令行失败
  140. )
  141. echo.
  142. echo.
  143. goto loop2
  144. :killMysql
  145. echo.
  146. echo 当前路径 %cd%
  147. echo.
  148. call taskkill /f /im %fileName%
  149. if %errorlevel% == 0 (
  150.  echo 杀死%setMysql%进程成功
  151. ) else (
  152.  echo 杀死%setMysql%进程失败
  153. )
  154. echo.
  155. echo.
  156. goto loop2
  157. :loop2
  158. echo ================ mysql ===============
  159. echo -------------------------------------
  160. echo 1. 选择mysql版本 1
  161. echo 2. 选择mysql功能 2
  162. echo ==========PRESS '0' TO QUIT==========
  163. echo.
  164. set input=
  165. set /p input=Please select a number:
  166. if /i '%input%'=='1' goto mysqlName
  167. if /i '%input%'=='2' goto yes
  168. if /i '%input%'=='0' goto end
  169. echo.
  170. echo.
  171. rem 输入错误跳回 input
  172. echo wrong number, try it again&&goto :loop
  173. goto end
  174. :no
  175. :end
  176. echo Good-bye!
  177. rem pause
  178. endlocal & @echo on

指定路径版

  1. @echo off & setlocal
  2. :loop
  3. set /p answer=Do you want to continue (y/n)
  4. echo You chose: %answer%
  5. if /i {%answer%}=={y} goto :mysqlName
  6. if /i {%answer%}=={n} goto :no
  7. echo.
  8. echo.
  9. echo Invalid selection, try again&&goto :mysqlName
  10. rem 选择mysqld.exe 的新名字
  11. :mysqlName
  12. echo ================ 选择mysql版本 ===============
  13. echo -------------------------------------
  14. echo 1. mysqld56
  15. echo 2. mysqld57
  16. echo 3. mysqld80
  17. echo ==========PRESS '0' TO QUIT==========
  18. echo.
  19. set inputn=
  20. set /p inputn=Please select a number:
  21. if /i '%inputn%'=='1' goto mysqld56s
  22. if /i '%inputn%'=='2' goto mysqld57s
  23. if /i '%inputn%'=='3' goto mysqld80s
  24. if /i '%inputn%'=='0' goto end
  25. echo.
  26. echo.
  27. rem 输入错误跳回 input
  28. echo wrong number, try it again&&goto :loop
  29. :mysqld56s
  30. set setMysql=mysqld56
  31. set fileName=%setMysql%.exe
  32. set currentDirss=D:\app\S_mysql\mysql-5.6.23-winx64\bin\%fileName%
  33. goto yes
  34. :mysqld57s
  35. set setMysql=mysqld57
  36. set fileName=%setMysql%.exe
  37. set currentDirss=D:\app\S_mysql\mysql-5.7.31-winx64\bin\%fileName%
  38. goto yes
  39. :mysqld80s
  40. set setMysql=mysqld80
  41. set fileName=%setMysql%.exe
  42. set currentDirss=D:\app\S_mysql\mysql-8.0.21-3336\bin\%fileName%
  43. goto yes
  44. :yes
  45. echo ================ 选择mysql功能 ===============
  46. echo.
  47. set currentDir=%currentDirss:~0,-13%
  48. set drives=%currentDirss:~0,2%
  49. SET dataFolder=%currentDir:~0,-3%data
  50. echo 查看mysql路径%currentDir%
  51. echo 启动的文件名:%fileName%
  52. echo cd 路径:%currentDir% %drives%
  53. echo data文件夹路径:%dataFolder%
  54. echo.
  55. echo -------------------------------------
  56. echo 1. 启动mysql 1
  57. echo 2. 进入mysql 2
  58. echo 3. 结束进程mysql 3
  59. echo ==========PRESS '0' TO QUIT==========
  60. echo.
  61. echo.
  62. set input=
  63. set /p input=Please select a number:
  64. if /i '%input%'=='1' goto startMysql
  65. if /i '%input%'=='2' goto goMysql
  66. if /i '%input%'=='3' goto killMysql
  67. if /i '%input%'=='0' goto end
  68. echo.
  69. echo.
  70. rem 输入错误跳回 input
  71. echo wrong number, try it again&&goto :mysqlName
  72. :startMysql
  73. echo.
  74. call taskkill /f /im %fileName%
  75. if %errorlevel% == 0 (
  76.  echo 杀死%setMysql%进程成功
  77. ) else (
  78.  echo 杀死%setMysql%进程失败
  79. )
  80. echo.
  81. echo Starting %setMysql% ...
  82. if exist %dataFolder% (
  83. rem 目录data已存在,无需创建
  84. echo 目录%dataFolder%目录已存在,无需创建!
  85. goto startMysqlSucceed
  86. ) else (
  87. rem 创建data目录,使用复制方法
  88. echo %dataFolder%目录不存在,已创建该目录!
  89. md %dataFolder%
  90. rem 3秒创建文件夹
  91. timeout /T 3 /NOBREAK
  92. rem 睡醒了
  93. cd /d %currentDir%
  94. call %setMysql% --initialize-insecure --console && (goto startMysqlSucceed) || goto startMysqlFailed
  95. )
  96. :startMysqlSucceed
  97. rem 睡三秒
  98. timeout /T 3 /NOBREAK
  99. cd /d %currentDir%
  100. echo 当前路径 %cd%
  101. start %fileName%
  102. echo 启动%setMysql%成功
  103. echo.
  104. echo.
  105. goto loop2
  106. :startMysqlFailed
  107. echo 初始化失败 删除文件夹
  108. rd /s /q %dataFolder%
  109. goto end
  110. :goMysql
  111. echo.
  112. echo.
  113. cd /d %currentDir%
  114. echo 当前路径 %cd%
  115. call mysql
  116. if %errorlevel% == 0 (
  117.  echo 启动%setMysql%命令行成功
  118. ) else (
  119.  echo 启动%setMysql%命令行失败
  120. )
  121. echo.
  122. echo.
  123. goto loop2
  124. :killMysql
  125. echo.
  126. echo 当前路径 %cd%
  127. echo.
  128. call taskkill /f /im %fileName%
  129. if %errorlevel% == 0 (
  130.  echo 杀死%setMysql%进程成功
  131. ) else (
  132.  echo 杀死%setMysql%进程失败
  133. )
  134. echo.
  135. echo.
  136. goto loop2
  137. :loop2
  138. echo ================ mysql ===============
  139. echo -------------------------------------
  140. echo 1. 选择mysql版本 1
  141. echo 2. 选择mysql功能 2
  142. echo ==========PRESS '0' TO QUIT==========
  143. echo.
  144. set input=
  145. set /p input=Please select a number:
  146. if /i '%input%'=='1' goto mysqlName
  147. if /i '%input%'=='2' goto yes
  148. if /i '%input%'=='0' goto end
  149. echo.
  150. echo.
  151. rem 输入错误跳回 input
  152. echo wrong number, try it again&&goto :loop
  153. goto end
  154. :no
  155. :end
  156. echo Good-bye!
  157. rem pause
  158. endlocal & @echo on