程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> 一鍵重置mysql的root暗碼劇本

一鍵重置mysql的root暗碼劇本

編輯:MySQL綜合教程

一鍵重置mysql的root暗碼劇本。本站提示廣大學習愛好者:(一鍵重置mysql的root暗碼劇本)文章只能為提供參考,不一定能成為您想要的結果。以下是一鍵重置mysql的root暗碼劇本正文


 @echo off 

title mysql 

::從注冊表找到Mysql的裝置途徑寫入文件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 
) 

::以”為分隔符,截取第二段內容保留到變量mysqlPath 
FOR /F tokens^=2^ 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% 

::假如最初一個字符不等於\,那末跳轉到GETPATH刪除mysqlPath的最初一個字符 
if not %character% == \ goto GETPATH 

::進入mysql裝置途徑C:\Program Files\MySQL\MySQL Server 5.0\bin 
cd /d "%mysqlPath%" 

::echo %mysqlPath% 

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

::禁用mysql辦事,跳過權限驗證修正暗碼 
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 

::由於是交互式,所以從文件讀取內容 
mysql <C:\config.tmp 
taskkill /F /IM mysqld-nt.exe 
net stop mysql >nul 
net start mysql 
del C:\config.tmp /F 
pause 
exit 

::刪除途徑最初一個字符,跳回主法式 
:GETPATH 
set mysqlPath=%mysqlPath:~0,-1% 
goto BACKTOMAIN

假如是用wamp一鍵裝置須要改一些劇本,重要是注冊表搜刮途徑轉變,前往值轉變,辦事名轉變了,mysql裝置途徑釀成D:\wamp\bin\mysql\mysql5.5.24\bin,少了mysqld-nt這個器械,過程外面也沒有mysqld-nt.exe

@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
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved