MySQL 的一些批处理

执行 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 ==========删除服务...===============
bin\mysqld --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 ==========安装服务...================================
bin\mysqld --install MySQL --defaults-file=%~dp0\my.ini
echo ==========初始化...(datadir 目录必须为空)==========
bin\mysqld --defaults-file=%~dp0\my.ini --initialize-insecure --console
echo ==========运行服务...================================
net start MySQL
echo ==========修改 root 密码...==========================
bin\mysql -u root --skip-password < change_password.sql
echo ==========结束!=====================================
pause

change_password.sql

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
exit

你可能感兴趣的:(MySQL 的一些批处理)