Home > Database > Mysql Tutorial > How to reset the initial password in Mysql8.0 and above

How to reset the initial password in Mysql8.0 and above

醉折花枝作酒筹
Release: 2021-06-01 09:35:08
forward
4465 people have browsed it

This article will introduce to you how to reset the initial password for Mysql8.0 and above. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.

How to reset the initial password in Mysql8.0 and above

Most of the methods on the Internet are to skip the Mysql password to connect by adding –skip-grant-tables in My.ini or My_default.ini. database and change the password.

I spent nearly three hours using online methods, hoping to use these methods to skip the database login password and change the initial password. This was a complete waste of three hours of my time.

After a period of exploration, I finally found a feasible method.

The following command line codes are all operated in administrator mode

Command line exe file directory: C:\Windows\System32\cmd.exe -> ; Right-click -> Run in "Administrator Mode"

Step 1: Close the Mysql service

First, make sure you have closed the Mysql service

cd c:\web\mysql-8.0.16\bin(此处输入自己的Mysql安装地址)
net stop mysql
Copy after login

How to reset the initial password in Mysql8.0 and above

Step 2: Skip Mysql password verification

After closing the Mysql service, continue operating in the C:\web\Mysql-8.0.16\bin directory

Enter

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

After entering this line of code, we have successfully skipped the Mysql password login

How to reset the initial password in Mysql8.0 and above

Step 3: None Enter Mysql with password

After the above steps, open a cmd.exe running in administrator mode

After entering the bin directory under mysql, log in to mysql directly

No You need to open the mysql service through net start mysql

Enter the following code in the command line

cd c:\web\mysql-8.0.16\bin(此处输入自己电脑上的安装目录)
mysql -u root -p
Copy after login

At this time, you will be prompted to enter the password, just press Enter, and you will be successful Connect to Mysql

How to reset the initial password in Mysql8.0 and above

Step 4: Set the login password to empty

Enter the code and set the password to empty (the password cannot be modified directly at this time, It must be set to empty first, otherwise an error will be reported)

Enter

use mysql; (使用mysql数据表)
update user set authentication_string='' where user='root';(How to reset the initial password in Mysql8.0 and above)
quit; (然后退出Mysql)
Copy after login

How to reset the initial password in Mysql8.0 and above

Step 5: Change your login password

Here are the points For both parts

1. Close the first cmd window (be sure to close!)

2. Enter the code

net in the second window stop mysql (turn off the mysql service, although it will show that the service is not enabled, but just in case)

net start mysql(then turn on the mysql service)

(Don’t be too troublesome here. If the previous mysql service is not closed, we will still log in without a password)

cd C:\web\mysql-8.0.16\bin

mysql -u root -p

(The password will be displayed here, just press Enter. We have left it blank in the fourth step)

ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password'; (Change password)

How to reset the initial password in Mysql8.0 and above

Last step: Verify whether the password is Modification successful

quit(退出mysql)
mysql -u root -p 
(输入新密码,再次登录)
成功~~~
Copy after login

Related recommendations: "mysql tutorial"

The above is the detailed content of How to reset the initial password in Mysql8.0 and above. For more information, please follow other related articles on the PHP Chinese website!

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