Overview
This note records a troubleshooting process for MySQL 8.0.42 on Windows 10 when the root password was forgotten and the database could not be accessed normally.
During the process, MySQL was started manually with --skip-grant-tables, but additional startup errors appeared, including named pipe configuration issues and datadir path errors.
This article summarizes the steps used to reset the MySQL root password and the checks needed when MySQL fails to start on Windows.
Environment
- OS: Windows 10
- Database: MySQL 8.0.42
- Account:
root - Tool: Command Prompt / MySQL command line client
- Configuration file:
my.ini - Common data directory path:
D:\ProgramData\MySQL\MySQL Server 8.0\Data
Problem
The MySQL root account password was forgotten. When trying to log in with:
mysql -u root -p
the login failed because the correct password was unknown.
The goal was to reset the root password and restore normal MySQL access.
Important Safety Note
Starting MySQL with --skip-grant-tables disables normal privilege checking temporarily. Use this mode only for local recovery and stop it as soon as the password reset is complete.
Do not expose a MySQL server running with --skip-grant-tables to a public or untrusted network.
Step 1: Stop the MySQL Service
Before starting MySQL in recovery mode, stop the running MySQL service.
You can stop it from Windows Services, or by using the command line:
net stop MySQL80
If your MySQL service name is different, replace MySQL80 with the actual service name.
Step 2: Start MySQL with --skip-grant-tables
Start mysqld manually and skip the permission tables:
mysqld --defaults-file="D:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console --skip-grant-tables
This mode allows connecting to MySQL without password authentication.
However, in this case, the following error appeared:
[ERROR] TCP/IP, --shared-memory, or --named-pipe should be configured on NT OS
This means MySQL did not have a valid communication method enabled when it was started manually.
Step 3: Start MySQL with Named Pipe Enabled
To solve the communication issue, start MySQL with --enable-named-pipe:
mysqld --defaults-file="D:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --enable-named-pipe --console --skip-grant-tables
After this, MySQL can be accessed through named pipe.
Step 4: Connect to MySQL Through Pipe
Open another Command Prompt window and connect to MySQL:
mysql -u root --protocol=PIPE
If the server was started successfully with --skip-grant-tables, you should be able to enter the MySQL shell without typing the old password.
Step 5: Select the MySQL System Database
Inside the MySQL shell, select the system database:
USE mysql;
Step 6: Reset the root Password
For MySQL 8.0, the password information is stored in the authentication_string field.
First, clear the existing authentication string for the root user:
UPDATE user
SET authentication_string = NULL
WHERE user = 'root';
Then flush privileges:
FLUSH PRIVILEGES;
After that, set a new password.
Replace NewPassword123! with your actual new password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword123!';
Finally, flush privileges again:
FLUSH PRIVILEGES;
Exit MySQL:
EXIT;
Step 7: Stop the Temporary MySQL Process
Go back to the Command Prompt window where mysqld is running and stop it with:
Ctrl + C
Then restart the normal MySQL service:
net start MySQL80
Now test the login again:
mysql -u root -p
Enter the new password. If everything is correct, the login should succeed.
Additional Issue: MySQL Failed to Start Because of datadir Error
During troubleshooting, MySQL also failed to start with a datadir related error.
Example error:
Failed to set datadir to 'D:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2)
This means MySQL was trying to use a data directory that did not exist.
In this case, the actual data directory was located under:
D:\ProgramData\MySQL\MySQL Server 8.0\Data
but the configuration pointed to:
D:\Program Files\MySQL\MySQL Server 8.0\data
The two paths are different.
Step 8: Check the my.ini Configuration File
Open the MySQL configuration file:
D:\ProgramData\MySQL\MySQL Server 8.0\my.ini
Check the [mysqld] section.
A correct example:
[mysqld]
port=3306
basedir="D:/Program Files/MySQL/MySQL Server 8.0/"
datadir="D:/ProgramData/MySQL/MySQL Server 8.0/Data/"
Make sure that:
basedirpoints to the MySQL installation directory.datadirpoints to the actual MySQL data directory.- The
Datadirectory exists. - The path uses correct slashes or escaped backslashes.
- There is no extra quotation mark or invalid character.
Step 9: Start MySQL Again
After fixing the my.ini file, try starting MySQL again:
net start MySQL80
Or start it manually for debugging:
mysqld --console
If the configuration is correct, MySQL should start normally.
Notes About InnoDB Recovery
During startup, MySQL may show messages about InnoDB recovery.
If the recovery fails with an assertion failure, it may indicate that the data directory is damaged or the configuration points to the wrong data files.
Before making risky changes, back up the entire data directory if possible:
D:\ProgramData\MySQL\MySQL Server 8.0\Data
Do not delete the data directory unless you are sure there is no important data inside.
Troubleshooting Checklist
If the password reset or MySQL startup still fails, check the following points:
- Is the MySQL service already running?
- Is the service name really
MySQL80? - Is the
my.inipath correct? - Does the
datadirdirectory actually exist? - Are
basediranddatadirpointing to different or incorrect locations? - Are you running Command Prompt as Administrator?
- Are there multiple MySQL versions installed on the same machine?
- Is MySQL being started from the correct installation directory?
- Did you stop the temporary
mysqld --skip-grant-tablesprocess after resetting the password?
Summary
The main recovery process was:
- Stop the MySQL service.
- Start
mysqldwith--skip-grant-tables. - If communication fails, add
--enable-named-pipe. - Connect with:
mysql -u root --protocol=PIPE
- Reset the
rootpassword. - Flush privileges.
- Restart the MySQL service normally.
- If MySQL still fails to start, check the
datadirpath inmy.ini.
This troubleshooting case shows that resetting the root password is not only about changing the password. On Windows, MySQL startup mode, named pipe configuration, service status, and datadir paths may all affect the recovery process.