One-Click Reset mysql root Password script, mysqlroot

Source: Internet
Author: User
Tags php and mysql

One-Click Reset mysql root Password script, mysqlroot

@ Echo off title mysql: find the installation path of mysqlfrom the registration table and write 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): separator, extract the second content and save it to the variable mysqlPath FOR/F tokens ^ = 2 ^ delims ^ = ^ "% I in (C: \ mysql.txt) do set mysqlPath = % I del C: \ mysql.txt/f: replace/with \ set mysqlPath = % mysqlPath:/=\% :: delete the last character of the path (this character is invisible, and may be a carriage return or a line break) set mys QlPath = % mysqlPath :~ 0,-1%: BACKTOMAIN: Get the last character of the path. The value is not equal to \ set character = % mysqlPath :~ -%: If the last character is not \, jump to GETPATH to delete the last character of mysqlPath if not % character % = \ goto GETPATH: Enter mysql installation path C: \ Program Files \ MySQL Server 5.0 \ bin cd/d "% mysqlPath %": echo % mysqlPath % if % errorlevel % neq 0 (echo MySQL not found pause exit ):: Disable the 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: \ co Nfig. tmp echo update user set password = password ("") where user = "root";> C: \ config. tmp echo flush privileges;> C: \ config. tmp echo exit> C: \ config. tmp: 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 the last character in the path and jump back to the main program: GETPATH set mysqlPath = % mysqlPath :~ 0,-1% goto BACKTOMAIN

If you use wamp for one-click installation, you need to change some scripts, mainly because the Registry Search Path is changed, the return value is changed, the service name is changed, and the mysql installation path is changed to D: \ wamp \ bin \ mysql \ mysql5.5.24 \ bin,mysqld-ntis missing, and mysqld-nt.exe is not included 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

Reset the mysql password in linux

Change the password. Execute the command in the bin directory of the mysql installation path.
./Mysqladmin-u root password 123
123 is the set secret.

Logon Test
Mysql-u root-p123

Mysql>
Mysql> show databases; view database
Mysql> quit exit

How can I reset the MySQL root password after I forget it?

1. KILL the MySQL (the best combination with PHP) process in the system;
2. Run the following command to start MySQL (the best combination with PHP) source code.
To start the service without checking the permissions;
MySQL (best combination with PHP) d_safe-skip-grant-tables &
3. Then use the empty password to log on to MySQL as the root user (the best combination with PHP );
MySQL (best combination with PHP)-u root
4. Modify the password of the root user;
MySQL (the best combination with PHP) update MySQL (the best combination with PHP ). user set password = PASSWORD ('new password') where User = 'root'; MySQL (the best combination with PHP) flush privileges; MySQL (the best combination with PHP) quit
5. Restart MySQL (the best combination of PHP and MySQL) to log on with the new password.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.