Home > Database > Mysql Tutorial > How to change the root password if you forget your password in MySQL8.0/8.x

How to change the root password if you forget your password in MySQL8.0/8.x

WBOY
Release: 2023-06-03 21:01:06
forward
2075 people have browsed it

1. Principle Description

1, authentication_stringThis is a new modification made by Mysql8.0. In the old version, the password() function was used.

2. Among the solutions to "mysql forgot password" found on the Internet, most of them will use UPDATE user SET authentication_string="12345" WHERE user="root"; to directly change the password Changing it to 12345 is actually a wrong usage. The authentication_string stores ciphertext. If it is changed directly to plain text such as "12345", it will cause the password to be incorrect and the login cannot be logged in.

The reason is that when the server verifies the identity, it will first convert the plaintext entered by the user into ciphertext and compare it with the ciphertext in the database to verify whether it matches, and it is obvious that it will directly put the plaintext where the ciphertext should be. Won't let them match successfully.

How to change the root password if you forget your password in MySQL8.0/8.x

3. In the similar online search result "mysql change password", alter user root@localhost identified by '12345' will be used to modify it. Password, this command cannot be used when "skipping the authorization table". It can only be used in normal mode.

How to change the root password if you forget your password in MySQL8.0/8.x

4 has such a solution. First change the authentication_string to empty. After all, the plaintext and ciphertext of empty values ​​are all empty values. Use the empty password to enter the mysql normal mode and then use alter to change the password.

How to change the root password if you forget your password in MySQL8.0/8.x

2. Solution steps

1, stop the mysql service

net stop mysql
Copy after login

How to change the root password if you forget your password in MySQL8.0/8.x

2, enter the command , enter the "skip authorization table" mode

mysqld --console --skip-grant-tables --shared-memory
Copy after login

How to change the root password if you forget your password in MySQL8.0/8.x

3. Put the previous cmd window aside, open another administrator cmd window, and enter mysqlEnter the mysql service

How to change the root password if you forget your password in MySQL8.0/8.x

4, enter use mysql to enter the mysql database, and then change authentication_string to empty

USE mysql;
UPDATE user SET authentication_string="" WHERE user="root";
Copy after login

How to change the root password if you forget your password in MySQL8.0/8.x

5, refresh permissions, exit

FLUSH privileges;
exit;
Copy after login

How to change the root password if you forget your password in MySQL8.0/8.x

6, in the first cmd window, use ctrl c to exit "Skip authorization Table" mode, start the mysql service

net start mysql
Copy after login

How to change the root password if you forget your password in MySQL8.0/8.x

7, use an empty password to log in, then use the alter statement to update the password, refresh the permissions, and exit

mysql -uroot -p
Copy after login
alter user root@localhost identified by '12345'
FLUSH privileges;
exit
Copy after login

How to change the root password if you forget your password in MySQL8.0/8.x

8, try to log in with password, successful.

How to change the root password if you forget your password in MySQL8.0/8.x

The above is the detailed content of How to change the root password if you forget your password in MySQL8.0/8.x. For more information, please follow other related articles on the PHP Chinese website!

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