I have not been using MySQL on my laptop for a long time. Today I have to start it, but I forgot the password. And I searched for it on the Internet, I tried a lot of ways to solve it, but I failed.
And then I found an effective solution.
I guess you tried this command before:
mysql -u root -p
Next, you tried to remember your password. Unfortunately, it shows like this:
Enter password: ***
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Then we are going to solve it step by step.
- Stop MySQL Preferences -> Search 'MySQL' in the top right corner (or find it on the panel) -> Click 'Stop MySQL Server'
2.Start MySQL Safe Mode
2.1 cd bin directory
cd /usr/local/mysql/bin
2.2 get permission
sudo su
2.3 enter the password of your laptop
Password:***
2.4 enter this command after sh-3.2#
./mysqld_safe --skip-grant-tables &
ATTENTION: START A NEW TERMINAL NOW
- Reset password 3.1 execute the command to skip the verification step ```
mysql -u -root
3.2 set the password to null
mysql> update user set authentication_string='' where user='root';
3.3 refresh permissions
flush privileges;
3.4
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'youPassword';"
3.5 exit and login MySQl again
exit
mysql -u root -p
I hope it is helpful for you.
Top comments (0)