Windows forgot MySQL root password how to restore

Source: Internet
Author: User
Tags flush safe mode

Solutions

Method One

1. Stop MySQL Service

Start-> run cmd, enter net stop MySQL at the command prompt window

2, switch the current directory to the MySQL installation path under the Bin directory

such as: CD C:mysql5bin

3, set no password login

Execute command mysqld-nt--skip-grant-tables


Note: 1 Ensure that the current directory is the MySQL bin directory, 2 if the prompt ' mysqld-nt ' is not an internal or external command, is not a running program or a batch file, please download the Mysqld-nt.rar.

4, login MySQL

Open a command Prompt window, switch the current directory to the MySQL bin directory, enter Mysql-u root-p


Null password login to MySQL.

5, set the new password for root

Enter Update Mysql.user set Password=password ("NewPassword") where user= "root";

6, Refresh the permission table and exit

Input flush Privileges;quit;

7. End Mysqld-nt.exe Process

Open Task Manager to end the Mysqld-nt.exe process.


Method Two

It is possible that your system does not have SAFE_MYSQLD programs (such as I now use the Ubuntu operating system, Apt-get installed MySQL), the following methods can be restored
1. Stop mysqld;
/etc/init.d/mysql stop
(You may have other methods, in short stop the mysqld run on it)
2. Use the following command to start MySQL, to do not check the permissions of the way to start;

The code is as follows Copy Code
Mysqld--skip-grant-tables &

3. Then use the null password method to log in to MySQL with root user;

The code is as follows Copy Code
Mysql-u Root

4. Change the password of root user;

The code is as follows Copy Code
mysql> Update Mysql.user Set Password=password (' NewPassword ') where user= ' root ';
mysql> flush Privileges;
Mysql> quit

Restart MySQL
/etc/init.d/mysql restart
You can log on using the new password NewPassword.


Another record forget the MySQL password to retrieve the method


If MySQL is running,
First Kill: Killall-term mysqld (if it is windows, call the process Manager directly, end)
Start mysq in Safe mode:

The code is as follows Copy Code
/usr/bin/safe_mysqld--skip-grant-tables &
(under Windows MySQL installation so disk/mysql/bin/safe_mysqld--skip-grant-tables)

You can enter MySQL without the need for a password.
Then it's

The code is as follows Copy Code
>use MySQL
>update User Set Password=password ("New_pass") where user= "root";
>flush privileges;

Re-kill MySQL, the normal way to start MySQL.

This method has not been tried, you can try.

Using Mysqladmin, this is a special case of the previous declaration.

The code is as follows Copy Code
Mysqladmin-u root-p Password mypasswd

After entering this command, you need to enter the original password for root, and then the root password will be changed to MYPASSWD. Change the command root to your username, and you can change your 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.