Home > Database > Mysql Tutorial > body text

Mysql can reset root password without password!

藏色散人
Release: 2022-01-05 15:35:03
forward
2072 people have browsed it

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

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

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

$ mysql
Copy after login

Successfully entered mysql

Switch to the MySQL system library mysql:

mysql> use mysql;
Copy after login

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

password字段改成了authentication_string。
Copy after login

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

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

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!

Related labels:
source:awaimai.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