How can I fix the loss of the root password in the MySQL database?

Source: Internet
Author: User

MySQLDatabaseLost root PasswordFirst, we need to end the mysql service process. And then in windows.

First, you can use the task manager to renew the instance. This should be mysql-nt.exe. Second, if your mysql is registered as a service, you can stop it in the service.

In linux or unix, kill the mysql service process directly. Then, use the -- skip-grant-tables option to start the mysql service. In windows, run mysql-nt -- skip-grant-tables in the bin directory of the mysql installation directory to start the mysql service, in this way, you can enter mysql with mysql-uroot-p without a password

In linux, the mysql directory is:/usr/bin/safe_mysqld -- skip-grant-tables. The command can be started. Under Freebsd, start/usr/local/etc/rc. d/mysql-server -- skip-grant-tables.

After entering mysql, execute the following statement:

 
 
  1. use mysql  
  2. update user set passwordpassword=password("new_pass")   
  3. where user="root" 
  4. flush privileges; 

Finally, let's end the current mysql service process. Restart your mysql instance to log on with the password you set.

How to restore the MySQL password:

Method 1:

If you forget the MySQL root Password, You can reset it using the following methods:

1. KILL the MySQL process in the system: killall-TERM mysqld

2. Run the following command to start MySQL without checking its permissions: safe_mysqld -- skip-grant-tables &

3. Then use the empty password to log on to MySQL as the root user.

4. Modify the password of the root user;

 
 
  1. Mysql> update mysql. user set password = PASSWORD ('new password') where User = 'root ';
  2. Mysql> flush privileges;
  3. Mysql> quit

Restart MySQL to log on with the new password.

Method 2:

1. stop MYSQL service. Open the DOS window in CMD and enter net stop mysql.

2. In the CMD command line window, enter the MYSQL installation directory, for example, d: \ mysql20080505 \ bin.

3. Enter the mysql security mode, that is, when mysql is up, it can enter the database without entering the password. Command: mysqld-nt -- skip-grant-tables

4. Open a new CMD command line window, enter mysql-uroot-p, use a blank password to log on to MySQL without entering a password, and press Enter)

5. Enter the following command to modify the password of the root user. Note: mysql. user has a "point" in the command ")

Mysql> update mysql. user set password = PASSWORD ('new password') where User = 'root ';

6. Refresh the permission table: mysql> flush privileges;

7. Exit

Mysql> quit MYSQL super Administrator account ROOT has been reset, then in the task manager to end the mysql-nt.exe this process, restart MYSQL! You can also directly restart the server) after MYSQL is restarted, you can log on to MYSQL with the newly set ROOT password!

The above is the remedy for the loss of the root password of the MySQL database and the restoration method for the MySQL database. This article will introduce it here. I hope this introduction will help you gain some benefits!

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.