标题: 修改MYSQL密码的BAT代码,不再为忘了密码而进行复杂的操作 [打印本页]
作者: find 时间: 2012-2-25 09:53 标题: 修改MYSQL密码的BAT代码,不再为忘了密码而进行复杂的操作
- @title ZEEEDA.COM MySQL密码修改工具
- @echo off
- @color 0a
- @ECHO ┏━━━━━━━━━━┥ 深圳指易达电子商务有限公司 ┝━━━━━━━━━┓
- @ECHO ┃ 提示: ┃
- @ECHO ┃ MySQL默认安装的服务名为MySQL ┃
- @ECHO ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- :confg_servnm
- set /p servnm=-^> 请输入MySQL的服务名(回车为默认的"MySQL":
- if "%servnm%"=="" set "%servnm%"=="MySQL"
- :reset_mydpwd
- set /p newpwd=-^> 请输入新的 root 密码:
- if "%newpwd%"=="" goto reset_mydpwd
- echo use MySQL >C:\mysqlpass.txt
- echo update user set password=password('%newpwd%') where user="root";>>C:\mysqlpass.txt
- echo flush privileges; >>C:\mysqlpass.txt
- net stop %servnm% 2>nul
- reg query "HKLM\SYSTEM\ControlSet001\Services\%servnm%" /t REG_EXPAND_SZ |find /i "image" >C:\mysql.txt
- if %errorlevel% neq 0 goto exit
- FOR /F "tokens=2,3* delims= " %%i in (C:\mysql.txt) do echo %%j %%k >C:\mysqltemp.txt
- FOR /F "tokens=1 delims=-" %%i in (C:\mysqltemp.txt) do set mysqlpath=%%i
- del C:\mysql.txt /f
- del C:\mysqltemp.txt /f
- set mysqlpath=%mysqlpath:/=\%
- set mysqlpath=%mysqlpath:"=%
- SET mysqlpath=%mysqlpath:~0,-6%
- if %mysqlpath:~-1% neq \ set mysqlpath=%mysqlpath:~0,-1%
- cd /d "%mysqlpath%"
- start mysqld-nt.exe --skip-grant-tables
- mysql <C:\mysqlpass.txt
- if %errorlevel% neq 0 goto out
- goto ok
- :exit
- echo 没有发现MYSQL
- pause
- del C:\mysqlpass.txt /f
- exit
- ut
- echo 密码设置失败
- pause
- del C:\mysqlpass.txt /f
- exit
- k
- del C:\mysqlpass.txt /f
- taskkill /f /im mysqld-nt.exe >nul
- @ECHO ┏━━━━━━━━━━┥ 深圳指易达电子商务有限公司 ┝━━━━━━━━━┓
- @ECHO ┃ ┃
- @ECHO ┃ root密码修改成功! ┃
- @ECHO ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
- echo www.zeeeda.com|clip
- net start %servnm%
- @pause
复制代码
http://bbs.chinaunix.net/thread-3675629-1-1.html
作者: conglin58 时间: 2012-3-2 05:23
试用看看!不用重装mysql了
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |