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