This article brings you a detailed explanation of the steps to reset the root password in mysql5.7. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.
After installing mysql5.7, I forgot my password and need to reset the root password;
Step one: Modify the configuration file to log in to mysql without a password
vim /etc/my.cnf ##在my.cnf的[mysqld]字段加入 skip-grant-tables ## 重启mysql服务 service mysqld restart
Step 2: Log in to mysql without a password
mysql -u root ##password直接回车
Step 3: Reset the root password to empty
mysql>use mysql; ## mysql 5.7.9以后废弃了password字段,字段名修改为authentication_string mysql>update user set authentication_string='' where user='root'; ## 刷新数据库 mysql>flush privileges;
Step 4 :root reset password
Exit mysql, delete the skip-grant-tables at the end of the /etc/my.cnf file, restart the mysql service, and log in as the root user. Because the authentication_string is set to empty above, it is unnecessary. Password login.
alter user 'root'@'localhost' identified by '#新密码#';
The merits are complete and the modification is successful
The above is the detailed content of Detailed explanation of the steps to reset the root password in mysql5.7. For more information, please follow other related articles on the PHP Chinese website!