Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
How to Find the Wi-Fi Password Using CMD in Windows
Next article icon

How to Reset MySQL Root Password in Windows Using CMD

Last Updated : 21 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Ever locked yourself out of your own database? It happens to the best of us! If you’ve forgotten your MySQL root password on a Windows machine, don’t panic. MySQL is a powerful database management system, and the root user has complete control over it meaning losing access can feel like a nightmare. But with the right steps, you can reset that password and regain control in no time.

Learn the process of resetting your MySQL root password using the Command Prompt (CMD). Also, the process we are going to explain in the below article will work for both Windows 11 and Windows 10.

How-to-Reset-MySQL-Root-Password-in-Windows-Using-CMD-copy
Reset MySQL Root Password in Windows Using CMD

Steps to Reset MySQL Root Password in Windows Using CMD?

Note: Before Resetting MySQL Root Password, make sure that you are Log in to your system as Administrator.

Step 1: Stop the MySQL server

  • Press Win+R and type the following command in the Run box and Click OK.
Command: services.msc

How-to-Reset-MySQL-Root-Password-in-Windows_1

  • Scroll down the list of services to find the MySQL service. Right-click that entry then left-clicks Stop.

For detailed guide, check out: How to Stop MySQL Server on Windows and Linux?

Step 2: Launch a Text Editor

  • Click on the menu and search for Notepad.
  • Alternatively, press Ctrl + Alt + N to open Notepad.

Step 3: Create a New Text File with the Password Command

  • Enter the following command to the text editor:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';

Note: Copy-paste this command to avoid any mistake. Make a new password and Replace 'NewPassword' with it.

How-to-Reset-MySQL-Root-Password-in-Windows_2

  • Use the File > Save As menu to save the file to the root of your hard drive (C:\ ). Choose a filename that makes sense, such as mysql-init.txt.

Consequently, the localhost command will make the password change on your local system. If you’re trying to change the password on a system over the network, substitute the hostname for localhost.

Step 4: Open a Command Prompt

  • Press Ctrl+Shift+Esc.
  • Then, click on the File menu > Run new task.
  • Type cmd.exe, and check the box to run as administrator.
  • Click OK.

Step 5: Restart the MySQL Server with Your New Config File

  • Navigate to the MySQL directory using the command prompt:
cd "C:\Program Files\MySQL\MySQL Server 8.0\bin"

Accordingly, the command line will show that you’re working in this folder.

  • Enter the following:
mysqld --init-file=C:\\mysql-init.txt

Note:

  • There are two slashes after the C: prompt.
  • Also, if you choose a different name in Step 2, use the same name after the double slash.

Step 6: Clean up

Now, you can log into your MySQL server as root using the new password.

  • Double-check to make sure it works. If you have unique configuration options (such as launching MySQL with a -defaults-file option), go ahead and do so.
  • Once MySQL launches, and you’ve confirmed the password change, delete the C:\myswl-init.txt file.

At this stage, you have successfully changed MySQL root password.

Conclusion

Resetting your MySQL root password on Windows is a straightforward process when using the Command Prompt. By following the steps outlined in this guide, you can efficiently recover your MySQL root password using CMD and regain control over your database. Whether you're a seasoned MySQL user or a beginner, this method ensures that you can handle password issues without unnecessary hassle. Keep this guide handy for future reference, so you're always prepared to reset your MySQL root password in Windows using CMD.

Also Read

  • MySQL | Change User Password
  • MySQL | Common MySQL Queries
  • learn SQL in 30 Days – From Basic to Advanced Level!
  • How to Find the Wi-Fi Password Using CMD in Windows?

Next Article
How to Find the Wi-Fi Password Using CMD in Windows

V

vishwajeetkjmp
Improve
Article Tags :
  • Misc
  • TechTips
  • DBMS
  • SQL
  • Command Prompt
Practice Tags :
  • Misc

Similar Reads

    How to Reset MySQL Root Password in Windows Using CMD?
    Ever locked yourself out of your own database? It happens to the best of us! If you’ve forgotten your MySQL root password on a Windows machine, don’t panic. MySQL is a powerful database management system, and the root user has complete control over it meaning losing access can feel like a nightmare.
    4 min read
    How to Find the Wi-Fi Password Using CMD in Windows
    Forgotten your Wi-Fi password? Don't worry you're not alone! Whether you're trying to connect a new phone, set up a smart TV, or help a friend get online, remembering complex Wi-Fi passwords can be a headache. Luckily, you don't need to reset your router or dig through old notebooks. Windows has a h
    7 min read
    How to Remove RAR/WinRAR Password Using CMD?
    Forgetting the password to your RAR or WinRAR file can be incredibly frustrating, especially when you need to access important data quickly. Fortunately, Command Prompt in Windows provides a powerful and effective way to remove the password from your RAR/WinRAR files without the need for third-party
    5 min read
    How to Reset Windows Admin Password?
    If you forgot your Windows administrator password, you might be locked out of your computer and unable to access your files and settings. However, there are some ways to reset your password without losing your data or reinstalling Windows. In this article, we will show you how to reset your Windows
    5 min read
    How to Stop MySQL Server on Windows and Linux?
    MySQL is one of the most popular open-source relational database management systems. Whether we are managing a small development setup or a production environment knowing how to start and stop MySQL servers is essential. In this guide, we will learn about the steps to start and stop MySQL servers on
    3 min read
    How to Change Windows Computer Password using CMD
    If you are a Windows user, one of the easiest ways to change your password is through the Command Prompt (CMD). This is especially helpful for users who prefer command-line tools or face issues accessing the standard settings menu.In this article, we’ll guide you through the steps to change your Win
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences