How to modify the password when the mysql database forgets the password?

Source: Internet
Author: User

How to modify or convert the password when the mysql database forgets the password?

When we forget the mysql database password, we will not be able to access the database normally, so we will not be able to change the password. How can we change the password now? Here we will teach you a simple and common way to change the password.

(If the figure shows a simple and quick password change, skip the query step and execute mysql → use mysql → update user set password = password ('123') as shown in the figure ') where user = 'root' and host = 'localhost';, the password is 123456)

Tools/Raw Materials
  • Mysql database
  • Cmd command line
Method/step
  1.  

    Open the folder where mysql.exeand mysqld.exe are located and copy the path.

  2.  

    Open the following command to enter the folder where mysql.exe is located.

  3.  

    Enter the command mysqld -- skip-grant-tables and press Enter. mysql user authentication is skipped. Note that after you enter this command, the command line cannot be operated. In this case, you can open a new command line. Note: before entering this command, run the mysqld.exe process in the task manager to ensure that the mysql server has finished running.

  4.  

    Then, enter mysql directly and press enter without any logon parameters to log on to the database.

  5.  

    Enter show databases. All databases are successfully logged on.

  6.  

    The mysql database is the place where the user name is saved. Enter use mysql and select mysql database.

  7.  

    Show tables: When you view all tables, you will find a user table, which stores account information such as user name, password, and permission.

  8.  

    Enter select user, host, password from user; To view account information.

  9.  

    Change the root password and enter update user set password = password ('20140901') where user = 'root' and host = 'localhost ';

  10.  

    View account information again. select user, host, password from user; you can see that the password has been modified.

  11.  

    Exit the command line, restart the mysql database, and try to log on with a new password.

  12.  

    The test showed that mysql could still be logged on without a password, but only two databases could be seen when the database was displayed. It indicates that the password verification skipped after the restart has been canceled.

  13.  

    The reason why I can log on without a password after I restart the database is that my database has an account without a password.

    END
Notes
  • Note the following:

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.