1. 由于编码问题我直接贴代码(ANSI编码)
@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
2. mysql ( my.ini )
[mysql]
# 设置 mysql 客户端默认字符集
default-character-set=utf8mb4
[mysqld]
#设置 3306 端口,不配置默认3306
port=3316
# 设置 mysql 的安装目录
basedir=D:\app\S_mysql\mysql-5.6.23-winx64
# 设置 mysql 数据库的数据的存放目录
datadir=D:\app\S_mysql\mysql-5.6.23-winx64\data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为 8 比特编码的 latin1 字符集
character-set-server=utf8mb4
# 免密码登录
skip-grant-tables
#时间戳问题, 不然会报错
explicit_defaults_for_timestamp=true
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3316
default-character-set=utf8
user=root
3. 注意事项
3.1 将下载好的mysql.zip解压
3.1.1 修改 ../bin/mysqld.exe文件问 mysqld版本号.exe
3..1.1.1 修改的同时请注意修改 启动脚本的
:mysqld56s
set setMysql=你修改后的名字;eg: 你改成了 mysqld12.exe,这里就填写 mysqld12。 下同
goto search
:mysqld57s
set setMysql=mysqld57
goto search
:mysqld80s
set setMysql=mysqld80
goto search
3.1.2 my.ini 文件复制到 ../mysql-5.6.23-winx64/根目录下
3.1.2.1 注意修改basedir datadir port
3.2 我设置的免密登录,如果要修改请将int文件中的[client]也做修改或 启动脚本中goMysql call mysql 做修改,要不然脚本的goMysql会失效
4. 参考