1: Open the my.cnf file (windows are my.ini), find mysqld, and then add the following skip-grant-tables, save the exit
2: Restart Service MySQL restart MySQL
3: connect to the database mysql -u root -p prompted for a password , you can directly enter into the database
4: select the mysql database mysql> use mysql
5: set a new password to the root user mysql> Update the user the sET password = password ( "newpassword") the WHERE the user = "root"
6: refresh database and exit mysql> flush privileges; mysql> quit ;
After changing for the better, and change it to my.cnf this document, we have just added to delete the "skip-grant-tables" line, save and exit and then restart the mysql service on it.