How to reset MySQL 8.x password on Windows

How to reset MySQL 8.x password on Windows
Author: Hannah
Date: 12/09/2024
Applicable to: Staff/client

Introduction

This article describes how to reset MySQL 8.x password on Windows server. This article takes MySQL 8.0 as an example.

1 Stop the MySQL server if it is running, find the MySQL service in the "Services" list and stop it

 
 

2 Create a text file containing the password-assignment statement on a single line. Replace the password with the password that you want to use.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

3 Save the file. This example assumes that you name the file . C:\resetpassword.txt

4 Open a console window to enter the command prompt and execute from the MySQL installation directory

5 Start the MySQL server with the init_file system variable set to name the file (notice that the backslash in the option value is doubled):

mysqld --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --init-file=C:\\Users\\Administrator\\Desktop\\resetpassword.txt
6.  Test whether the new password can log in correctly
mysql -uroot -pHannah_newpasswd
7.  After the MySQL service is successfully started, delete resetpassword.txt

Add Feedback