Home >Database >Mysql Tutorial >Mysql can reset root password without password!

Mysql can reset root password without password!

藏色散人
藏色散人forward
2022-01-05 15:35:032121browse

MySQL reset root password

We introduce a way to reset the root password without a password.

The steps are as follows:

1. Open the configuration file /etc/my.cnf and add a line of skip-grant-tables under mysqld, as follows:

[mysqld]
#...
skip-grant-tables
#...

In this way we You can now log in to MySQL without a password.

Then save and exit.

2. Restart MySQL

Choose 1 of these two commands:

$ sudo systemctl restart mysqld
$ sudo service mysqld restart

3. Enter mysql in the terminal to log in to the MySQL database directly:

$ mysql

Successfully entered mysql

Switch to the MySQL system library mysql:

mysql> use mysql;

5. Reset the root password
It should be noted that after MySQL5.7, there is no password field,

password字段改成了authentication_string。

To change the password, we need to change the value of this field.

update user set authentication_string=password('新密码') where user='root';

In this way, we have successfully changed the password.
5. Modify the /etc/my.cnf file and comment out the skip-grant-tables sentence added previously.

Otherwise we will still log in to Mysql without a password.

6. Restart MySQL again and you're done.

Recommended learning: "mysql video tutorial"

The above is the detailed content of Mysql can reset root password without password!. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:awaimai.com. If there is any infringement, please contact admin@php.cn delete