MySQL forgot root password solution

Source: Internet
Author: User

My test machine for a long time did not use MySQL, the password forgotten, now need to login, and then change the password, the steps are as follows:

1. Stop the database

/etc/init.d/mysqld stop

2. Modify MY.CNF

Modify the My.cnf file to add Skip-grant-tables in the mysqld process configuration file
#在这里, if you forget where my.cnf is, you can use the: sudo find/-name my.cnf command to find it.

3. Restart the database

/etc/init.d/mysqld start

4. Change the root password

Direct use command: mysql-u root-p command [Enter login without entering the password directly]
Modify root password: Update mysql.user set password=password ('newpassword' where user='root'

5. Restart the database

You need toDelete or comment out the skip-grant-tables in my.cnf, and then restart the database. Note: If there is no comment then the next time you log in, you will still not need a password. 

MySQL forgot root password solution

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.