@echo off title MySQL:: Find the MySQL installation path from the registry write file Mysql.txt reg Query Hklm\system\controlset001\services\mysql | find/i "ImagePath" >c:\mysql.txt if%errorlevel% neq 0 (echo mysql not found pause exit):: With "as separator, intercept the second paragraph and save it to a variable Mysqlpath for/f tokens^=2^ delims^=^ "%%i in (C:\mysql.txt) do set mysqlpath=%%i del c:\mysql.txt/f:: path/replace with \ Set mysqlpath=%mysqlpath:/=\%:: Deletes the last character of the path (the character is not visible, possibly a carriage return, and so on) set mysqlpath=%mysqlpath:~0,-1%: Backtomain:: Get the last character of the path to see Not equal to \ Set character=%mysqlpath:~-1,1%:: If the last character is not equal to \, then jump to getpath delete Mysqlpath last character if not%character% = = = Goto GETPA TH:: Enter the MySQL installation path C:\Program files\mysql\mysql Server 5.0\bin cd/d "%mysqlpath%":: Echo%mysqlpath% if%errorlevel% NEQ 0 (Echo mysql not found pause exit):: Disable MySQL service, skip permission validation modify password taskkill/f/im mysqld-nt.exe net stop MySQL > Nul start/b mysqld-nt--skip-grant-tables ping-n 2 127.0.0.1 >nul echo use MySQL >c:\config.tmp echo us ER set Password=password ("") wheRe user= "root"; >>c:\config.tmp echo flush privileges; >>c:\config.tmp Echo Exit >>c:\config.tmp:: Read content from file MySQL <c:\config.tmp taskkill/f/im mysq because it is interactive Ld-nt.exe net stop MySQL >nul net start MySQL del c:\config.tmp/f pause exit:: Delete the last character of the path, skip back to Main program: GetPath set mysqlpath=%mysqlpath:~0,-1% Goto Backtomain
If you are using Wamp one-click installation needs to change some scripts, mainly the registry search path changes, return value change, service name changed, MySQL installation path into D:\wamp\bin\mysql\mysql5.5.24\bin, less mysqld-nt this thing, There is no mysqld-nt.exe in the process either.
@echo off title MySQL reg Query Hklm\system\controlset001\services\wampmysqld | find/i "ImagePath" >c:\mysql.txt if%errorlevel% neq 0 (echo mysql not found pause exit) for/f "Tokens=3 del Ims= "%%i in (C:\mysql.txt) do set mysqlpath=%%i del c:\mysql.txt/f set mysqlpath=%mysqlpath:/=\% set MYSQLPATH=%MYSQ lpath:~0,-1%: Backtomain set character=%mysqlpath:~-1,1% if not%character% = = \ Goto GetPath cd/d "%mysqlpath%": : Echo%mysqlpath% if%errorlevel% neq 0 (echo MySQL not found pause exit) taskkill/f/im mysqld.exe net stop W
Ampmysqld >nul start/b mysqld-nt--skip-grant-tables ping-n 2 127.0.0.1 >nul echo use MySQL >c:\config.tmp echo Update user set Password=password ("") where user= "root"; >>c:\config.tmp echo flush privileges; >>c:\config.tmp Echo exit >>c:\config.tmp mysql <c:\config.tmp taskkill/f/im mysqld.exe net stop WA Mpmysqld >nul net start wampmysqld del c:\config.tmp/f pause exit
: GetPath set mysqlpath=%mysqlpath:~0,-1% goto Backtomain