A key to reset the MySQL root password implementation script.
@echo off
Title MySQL
:: The installation path for MySQL found from the registry is written to the 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
)
:: Take "as delimiter, intercept the second paragraph to save to variable Mysqlpath
for/f tokens^=2^ delims^=^ "%%i in (C:\mysql.txt) do set mysqlpath=%%i
Del c:\mysql.txt/f
:: In path/replace with \
Set mysqlpath=%mysqlpath:/=\%
:: Delete the last character of the path (the character is not visible, it may be a carriage return, etc.)
Set mysqlpath=%mysqlpath:~0,-1%
: Backtomain
:: Gets 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 to delete the last character of Mysqlpath
If not%character% = = \ Goto GetPath
:: Enter 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
) www.jbxue.com
:: Disable MySQL service, skip permission verification, change 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 Update user set Password=password ("") where user= "root"; >>c:\config.tmp
echo Flush privileges; >>c:\config.tmp
Echo Exit >>c:\config.tmp
:: Read content from a file because it is interactive
MySQL <c:\config.tmp
taskkill/f/im Mysqld-nt.exe
net stop MySQL >nul
net start MySQL
Del c:\config.tmp/f
Pause
Exit
:: Delete path last character, jump 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 is the registry search path changes, return value changes, service name changed, MySQL installation path into D:\wamp\bin\mysql\mysql5.5.24\bin, less mysqld-nt this thing, There's no mysqld-nt.exe in the process.
@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 delims="%%i in (C:\mysql.txt) do set mysqlpath=%%i
Del c:\mysql.txt/f
Set mysqlpath=%mysqlpath:/=\%
Set mysqlpath=%mysqlpath:~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 Wampmysqld >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 Wampmysqld >nul
net start Wampmysqld
Del c:\config.tmp/f
Pause
Exit
: GetPath
Set mysqlpath=%mysqlpath:~0,-1%
Goto Backtomain