1. 由于编码问题我直接贴代码(ANSI编码)
@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
2. mysql ( my.ini )
[mysql]  # 设置 mysql 客户端默认字符集  default-character-set=utf8mb4[mysqld]#设置 3306 端口,不配置默认3306port=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=INNODBsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES[client]# 设置mysql客户端连接服务端时默认使用的端口port=3316default-character-set=utf8user=root
3. 注意事项
3.1 将下载好的mysql.zip解压
3.1.1  修改 ../bin/mysqld.exe文件问 mysqld版本号.exe
3..1.1.1 修改的同时请注意修改 启动脚本的
:mysqld56sset setMysql=你修改后的名字;eg: 你改成了 mysqld12.exe,这里就填写 mysqld12。 下同goto search:mysqld57sset setMysql=mysqld57goto search:mysqld80sset setMysql=mysqld80goto 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. 参考