Home > Database > Mysql Tutorial > Detailed explanation of the steps to reset the root password in mysql5.7

Detailed explanation of the steps to reset the root password in mysql5.7

不言
Release: 2019-01-23 11:42:43
forward
4766 people have browsed it

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
Copy after login

Step 2: Log in to mysql without a password

mysql -u root 
##password直接回车
Copy after login

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;
Copy after login

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 '#新密码#';
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template