执行 SQL 脚本文件(https://blog.csdn.net/vebasan/article/details/7619911):
mysql –u root –p 123456 < script.sql
卸载 MySQL(需手动删除文件):
@echo off echo ==========获取管理员权限...========= %1 %2 ver|find "5.">nul&&goto :gotAdmin mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :gotAdmin","","runas",1)(window.close)&goto :eof :gotAdmin cd /d %~dp0 echo ==========停止服务...=============== net stop MySQL echo ==========删除服务...=============== binmysqld --remove echo ==========结束!==================== pause
安装 MySQL(my.ini 这里是在上级文件夹中存储):
@echo off echo ==========获取管理员权限...========================== %1 %2 ver|find "5.">nul&&goto :gotAdmin mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :gotAdmin","","runas",1)(window.close)&goto :eof :gotAdmin cd /d %~dp0 echo ==========安装服务...================================ binmysqld --install MySQL --defaults-file=%~dp0my.ini echo ==========初始化...(datadir 目录必须为空)========== binmysqld --defaults-file=%~dp0my.ini --initialize-insecure --console echo ==========运行服务...================================ net start MySQL echo ==========修改 root 密码...========================== binmysql -u root --skip-password < change_password.sql echo ==========结束!===================================== pause
change_password.sql
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'; exit