安装命令
@ECHO OFF
if "%1"=="h" goto begin
start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
fltmc>nul||cd/d %~dp0&&mshta vbscript:CreateObject("Shell.Application").ShellExecute("%~nx0","%1","","runas",1)(window.close)&&exit
if not "%OS%"=="Windows_NT" exit
@echo 设置环境变量
@SET servicesName=MySql
@SET sqlpath=%~dp0
@echo %sqlpath%;%path%
@setx /M PATH "%sqlpath%bin;%path%"
@echo 初始化数据库配置文件
@del %sqlpath%my.ini
@echo %sqlpath%my.ini
@echo [mysqld]>>%sqlpath%my.ini
@echo port=3306>>%sqlpath%my.ini
set mybasedir=%sqlpath:\=/%
@echo basedir=%mybasedir%>>%sqlpath%my.ini
@echo datadir=%mybasedir%data>>%sqlpath%my.ini
@echo max_connections=200>>%sqlpath%my.ini
@echo max_connect_errors=10>>%sqlpath%my.ini
@echo character-set-server=utf8mb4>>%sqlpath%my.ini
@echo default-storage-engine=INNODB>>%sqlpath%my.ini
@echo group_concat_max_len = 102400>>%sqlpath%\my.ini
@echo max_allowed_packet = 100M>>%sqlpath%\my.ini
@echo default_authentication_plugin=mysql_native_password>>%sqlpath%\my.ini
@echo [mysql]>>%sqlpath%my.ini
@echo default-character-set=utf8mb4>>%sqlpath%my.ini
@echo [client]>>%sqlpath%my.ini
@echo default-character-set=utf8mb4>>%sqlpath%my.ini
@echo port=3306>>%sqlpath%\my.ini
@echo 数据库配置中
@echo %sqlpath%bin\mysqld.exe
@%sqlpath%bin\mysqld.exe --initialize-insecure --lower-case-table-names=1 --user=mysql --console
@echo 开始安装数据库
@%sqlpath%\bin\mysqld.exe --install %servicesName%
@net start %servicesName%
@echo 初始化密码开始
@%sqlpath%\bin\mysql.exe -uroot < %sqlpath%\setpwd.sql
@echo 初始化密码结束
@echo 数据库安装完成
@echo port=3306>>%sqlpath%\my.ini 设置mysql端口
@%sqlpath%\bin\mysqld.exe --install %servicesName% 安装mysql到服务中以及服务名
setpwd.sql文件
use mysql;
select Host, User from user;
update user t set authentication_string='' where t.user='root';
update user set host='%' where user='root';
flush privileges;
alter user 'root'@'%' IDENTIFIED WITH mysql_native_password BY '1234';
flush privileges;
create database test;
设置root权限,设置root密码脚本。
卸载mysql
@ECHO OFF
if "%1"=="h" goto begin
start mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
fltmc>nul||cd/d %~dp0&&mshta vbscript:CreateObject("Shell.Application").ShellExecute("%~nx0","%1","","runas",1)(window.close)&&exit
if not "%OS%"=="Windows_NT" exit
@echo 卸载mysql
@SET sqlpath=%~dp0
@SET servicesName=MySql
net stop %servicesName%
mysqld --remove %servicesName%
rmdir %sqlpath%\my.imi
@pause
标签:sqlpath%,windows,mysql,echo,--,始化,MySql,my,ini
From: https://blog.csdn.net/gf_gfh/article/details/139441398