How to log in MySQL forgot password

How to log in MySQL forgot password

  1. Edit mysql configuration file
vim /etc/my.cnf
....
'// 在文件的[mysqld]标签下添加一句:skip-grant-tables  '

Then save and exit.

  1. Restart the database
systemctl restart mysqld
  1. Login mysql database without password
mysql -u root 
  1. change Password
mysql> use mysql;
mysql> update mysql.user set authentication_string=password('abc123') where user='root';    
'//  其中abc123为重新设置的密码,可以任意设置。'
  1. Comment out the skip-grant-tables added in step 1, and restart the server, you can log in to the server with the password you just modified.
 mysql -uroot -pabc123

Guess you like

Origin blog.csdn.net/qq_46480020/article/details/111940655