windows MySql 8免安装初并始化root权限和密码

安装命令

@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

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值