Mysql5.7:​​下载地址 ​

 

初始my.ini

@setlocal enabledelayedexpansion
@echo off
color f0
rem 阿里云主机服务器。
title MYSQL已安装

rem 下面为自定义参数可修改
set mysqlServiceName=MySQL7506
set iniFileName=my1.ini
set mysqlPort=7506

set basedir=%~dp0
set bin=%~dp0\bin
cd /d %~dp0
if exist !bin!\mysqld.exe (
rem 写入配置
if exist !iniFileName! (
echo !iniFileName! 配置文件已存在
) else (
>!iniFileName! echo [mysqld]
>>!iniFileName! echo #skip-grant-tables
>>!iniFileName! echo # 设置!mysqlPort!端口
>>!iniFileName! echo port=!mysqlPort!
>>!iniFileName! echo max_allowed_packet=500M
>>!iniFileName! echo # 设置mysql的安装目录
>>!iniFileName! echo basedir=!basedir!\\ # 切记此处一定要用双斜杠\\,单斜杠我这里会出错。
>>!iniFileName! echo # 设置mysql数据库的数据的存放目录
>>!iniFileName! echo datadir=!basedir!\\Data # 此处同上
>>!iniFileName! echo # 开启 MySQL 服务器 SSL 特性
>>!iniFileName! echo ssl
>>!iniFileName! echo # 根证书
>>!iniFileName! echo ssl-ca= !basedir!ssl\\ca.pem
>>!iniFileName! echo # 服务器公钥
>>!iniFileName! echo ssl-cert= !basedir!ssl\\server-cert.pem
>>!iniFileName! echo #服务器私钥
>>!iniFileName! echo ssl-key=!basedir!ssl\\server-key.pem
>>!iniFileName! echo # 允许最大连接数
>>!iniFileName! echo max_connections=200
>>!iniFileName! echo # 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
>>!iniFileName! echo max_connect_errors=10
>>!iniFileName! echo # 服务端使用的字符集默认为UTF8
>>!iniFileName! echo character-set-server=utf8
>>!iniFileName! echo # 创建新表时将使用的默认存储引擎
>>!iniFileName! echo default-storage-engine=INNODB
>>!iniFileName! echo # 默认使用“mysql_native_password”插件认证
>>!iniFileName! echo default_authentication_plugin=mysql_native_password
>>!iniFileName! echo [mysql]
>>!iniFileName! echo # 设置mysql客户端默认字符集
>>!iniFileName! echo default-character-set=utf8
>>!iniFileName! echo [client]
>>!iniFileName! echo # 设置mysql客户端连接服务端时默认使用的端口
>>!iniFileName! echo port=!mysqlPort!
>>!iniFileName! echo default-character-set=utf8
>>!iniFileName! echo #ssl-ca=!basedir!ssl\\ca-cert.pem
>>!iniFileName! echo #ssl-cert=!basedir!ssl\\server-cert.pem
>>!iniFileName! echo #ssl-key=!basedir!ssl\\server-key.pem
)
)

pause
:end

 

 

安装

@setlocal enabledelayedexpansion
@echo off
color f0
title 一键安装

rem 下面为自定义参数可修改
set mysqlServiceName=MySQL7506
set iniFileName=my.ini

set basedir=%~dp0
set bin=%~dp0\bin
set timeConfig=!basedir!config.tmp
cd /d %~dp0

%bin%\mysqld --defaults-file=%basedir%\my.ini --initialize --user=mysql --console
if %errorlevel% == 0 (
echo MYSQL初始化成功,开始安装...
) else (
echo MYSQL已初始化,开始安装...
)
%bin%\mysqld --install !mysqlServiceName! --defaults-file=!basedir!\!iniFileName!
rem 启动服务
echo 开始启动MYSQL服务
net start !mysqlServiceName!

:end
pause

 

 

批处理 mysql5.7 一键安装 (Windows)_mysql

 

 

 

批处理 mysql5.7 一键安装 (Windows)_mysql_02

批处理 mysql5.7 一键安装 (Windows)_初始化_03

@setlocal enabledelayedexpansion
@echo off
color f0
title MYSQL一键安装

set basedir=%~dp0
set bin=%~dp0\bin
set myiniFile=my.ini
cd /d %~dp0
if exist !bin!\mysqld.exe (
rem 写入配置
if exist %myiniFile% (
echo %mysiniFile% 配置文件已存在
) else (
>my.ini echo [mysqld]
>>my.ini echo port=3306
>>my.ini echo basedir=!basedir!
>>my.ini echo datadir=!basedir!\Data
>>my.ini echo log-error=!basedir!\Logs.log
>>my.ini echo max_connections=200
>>my.ini echo max_connect_errors=10
>>my.ini echo character-set-server=utf8mb4
>>my.ini echo default-storage-engine=INNODB
>>my.ini echo default_authentication_plugin=mysql_native_password
>>my.ini echo local_infile=ON
>>my.ini echo.
>>my.ini echo [mysql]
>>my.ini echo default-character-set=utf8mb4
>>my.ini echo local_infile=ON
>>my.ini echo.
>>my.ini echo [client]
>>my.ini echo port=3306
>>my.ini echo default-character-set=utf8mb4
)

rem 添加环境变量
echo 开始检查环境变量...
echo.
for /f "tokens=2*" %%i ^
in ('reg query "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v Path^|findstr /i "path"') ^
do (set "p=%%j")
for /f "tokens=*" %%a in ('echo !p! ^| find /i "!bin!"') do (set flag=1)
if not defined flag (
echo 开始添加环境变量
setx Path "!p!;!bin!" /M | find "成功" && echo 环境变量添加成功
set p=!Path!
) else (
echo 环境变量已存在,无需设置。
)
echo.

rem 初始化 --console
cd !bin!

>!basedir!\Logs.log echo --------初始化数据库开始--------

echo 开始初始化数据库

mysqld --initialize-insecure

>>!basedir!\Logs.log echo --------初始化数据库结束--------

rem 安装服务
echo 开始安装服务
mysqld --install MySQL | find "successfully" && echo 服务安装成功
echo.
rem 启动服务
echo 开始启动MYSQL服务
net start MySQL
echo.

mysql -u root -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '1qaz'";

echo 安装完成
) else (
echo 请将本工具放在解压后的MYSQL根目录下再打开
)
pause

View Code

 

安装