Skip to content
geeksforgeeks
  • 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
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • 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 Reset Windows Admin Password?
Next article icon

How to Reset MySQL Root Password in Windows Using CMD?

Last Updated : 07 Apr, 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.

In this step-by-step guide, we’ll walk you through the process of resetting your MySQL root password using the Command Prompt (CMD). Also, the process we are going to explain the 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

How 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 Reset Windows Admin Password?

V

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

Similar Reads

  • How to Find the Wi-Fi Password Using CMD in Windows
    Forgotten your Wi-Fi password? Need to connect a new device but can’t recall the complex string of characters? You don’t have to scramble for that sticky note or reset your router just yet! Hidden within Windows is a powerful, built-in tool that lets you retrieve your Wi-Fi password quickly and secu
    8 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 Check Open Ports Using CMD in Windows?
    Open ports on your Windows computer act like doors for data-letting information in and out. While necessary for apps and services, unprotected ports can become security risks. Checking which ports are open helps you spot vulnerabilities, fix connection issues, and keep your system safe. Using Comman
    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 Wi
    4 min read
  • How to Remove Windows 10 Password?
    Looking to remove your Windows 10 password for a faster login experience? Whether you want to disable the password on Windows 10 or simply streamline the login process, this guide will walk you through the steps to turn off the Windows 10 login password. By following these easy steps, you'll learn h
    4 min read
  • How to Find Connected WiFi Password in Windows?
    If you're connected to a WiFi network but can't remember the password, don't worry—Windows allows you to retrieve it easily. Whether you need to connect a new device or share the password with someone else, finding the connected WiFi password in Windows is a straightforward process. This guide will
    3 min read
  • How to Repair Windows 10 Using Command Prompt - 5 Methods
    Is your Windows 10 not working right? Maybe it’s slow, keeps crashing, or won’t start properly. These problems can be annoying, but you don’t have to do something big like reinstalling Windows yet. There’s a handy tool called Command Prompt that can fix many Windows issues, and it’s already on your
    6 min read
  • How to use CMD for Python in Windows 10?
    Using the Command Prompt (CMD) is an effective way to interact with Python on your Windows 10 machine. Whether you're writing scripts, testing code, or running programs, mastering CMD for Python in Windows 10 is crucial. This article will guide you on how to run Python in CMD, execute scripts, and t
    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