SoFunction
Updated on 2025-03-09

Implementation script for resetting mysql's root password with one click

Implementation script for resetting mysql's root password with one click

Updated: September 9, 2014 16:57:43 Submission: whsnow
This article mainly introduces the implementation script for resetting the root password of mysql with one click. It is more practical. Friends who need it can refer to it.

There are many ways to reset mysql's root password. This article introduces it to use batch processing to complete it.

@echo off

title mysql

::Find it from the registryMysqlThe installation path is written to the file
reg query HKLM\SYSTEM\ControlSet001\Services\MySQL | find /I "ImagePath">C:\
if %errorlevel% neq 0 (
echo MySQL not found
pause
exit
)

::by”as a separator,Snap the second paragraph and save it to a variablemysqlPath
FOR /F tokens^=2^ delims^=^" %%i in (C:\) do set mysqlPath=%%i
del C:\ /f

::In the path/Replace with\
set mysqlPath=%mysqlPath:/=\%

::Delete the last character of the path(This character is not visible,Maybe it's carriage return or something like that)
set mysqlPath=%mysqlPath:~0,-1%

:BACKTOMAIN

::The last character of the path is not equal to\
set character=%mysqlPath:~-1,1%

::If the last character is not equal to\,Then jump toGETPATHdeletemysqlPathThe last character
if not %character% == \ goto GETPATH

::EntermysqlInstallation pathC:\Program Files\MySQL\MySQL Server 5.0\bin
cd /d "%mysqlPath%"

::echo %mysqlPath%

if %errorlevel% neq 0 (
echo MySQL not found
pause
exit
) 

::DisabledmysqlServe,Skip permission verification to modify password
taskkill /F /IM 
net stop mysql >nul
start /b mysqld-nt --skip-grant-tables
ping -n 2 127.0.0.1 >nul
echo use mysql >c:\
echo update user set password=password("") where user="root";>>C:\
echo flush privileges; >>C:\
echo exit >>C:\

::Because it's interactive,所by从文件读取内容
mysql <C:\
taskkill /F /IM 
net stop mysql >nul
net start mysql
del C:\ /F
pause
exit

::Delete the last character of the path,Jump back to the main program
:GETPATH
set mysqlPath=%mysqlPath:~0,-1%
goto BACKTOMAIN
If it is usedwampOne-click installation requires some scripts,Mainly, the registry search path changes,Change of return value,Serve名改变了,mysqlInstallation path变成D:\wamp\bin\mysql\mysql5.5.24\bin,Lessmysqld-ntThis thing,There is no in the process
@echo off

title mysql

reg query HKLM\SYSTEM\ControlSet001\Services\wampmysqld | find /I "ImagePath">C:\

if %errorlevel% neq 0 (
echo MySQL not found
pause
exit
)

FOR /F "tokens=3 delims= " %%i in (C:\) do set mysqlPath=%%i
del C:\ /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 
net stop wampmysqld >nul
start /b mysqld -nt --skip-grant-tables
ping -n 2 127.0.0.1 >nul
echo use mysql >c:\
echo update user set password=password("") where user="root";>>C:\
echo flush privileges; >>C:\
echo exit >>C:\

mysql <C:\

taskkill /F /IM 
net stop wampmysqld >nul
net start wampmysqld
del C:\ /F

pause
exit

:GETPATH
set mysqlPath=%mysqlPath:~0,-1%
goto BACKTOMAIN
  • root password

Related Articles

  • How to set the time to turn off the monitor in win7

    Set the time to turn off the monitor, which can be simply implemented through batch processing. Interested friends can learn about this article
    2013-12-12
  • Summary of methods for batch deletion of folders as required using batch processing

    A batch file is an unformatted text file that contains one or more commands. Its extension is .bat or .cmd. Type the name of the batch file at the command prompt, or double-click the batch file, and the system will call to run each command in the file one by one in the order in which each command appears. Using batch files can simplify daily or repetitive tasks.
    2015-09-09
  • dos Date and Time format settings use summary (Date and Time)

    In fact, the date format obtained under dos is to obtain the pointer offset, and the number after the comma indicates the extracted character length.
    2012-06-06
  • Preprocessing implementation code in batch processing

    If you are familiar with the processing mechanism of the character "^" off-character character, you can continue reading. Please refer to the relevant articles on delineated characters first.
    2011-01-01
  • BAT parameters to dequote (various weird ways to dequote)

    This article mainly introduces BAT parameters to dequote marks and various strange ways to dequote marks. Friends who need it can refer to it.
    2014-06-06
  • The little secret of ping command

    The little secret of ping command...
    2007-03-03
  • Batch File Classification Organizer

    Classify files under the current directory and all subdirectories.
    2009-05-05
  • What commands should be used to check the hard disk partition under DOS

    There are many ways to view hard disk partitions. This article will introduce to you how to view hard disk partitions under DOS. Friends who need it can refer to it.
    2014-03-03
  • Batch Process Code to end the McCafe process

    I wrote a batch process that ended the McCafee process before. I don’t know if it can be used for all versions of McCafee. Anyway, it’s easy to use on my mcafee virusscan enterprise ver8.5.
    2009-03-03
  • Batch processing of pronunciation of words or sentences

    Batch code for pronunciation of words or sentences, friends who need it can refer to it
    2012-05-05

Latest Comments