If you forgot your root password and need to reset it for your MySql 8
server. Follow below guide.
Stop MySQL80 service on Windows
- Open PowerShell as Administrator and execute the below command.
get-service -Name mysql* | Stop-Service
This will stop the MySQL80 service. If you wish to stop service from the services console, you can go to Start menu
, select Control Panel
, then Administrative Tools
, then Services
.
Okay, now that we have stopped the service. Let’s proceed with root password reset.
MySQL Root Password Reset
- Create a file called
reset.txt
on your computer atc:\reset.txt
. - Copy and paste below to
reset.txt
file and replacepassword
with your own password and save.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
- Open Command promote and go to bin path
cd C:\Program Files\MySQL\MySQL Server 8.0\bin
- Execute below command to reset password:
mysqld.exe --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --datadir="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Data" --init-file=c:\\reset.txt --console
Your output should look something like this:
C:\Program Files\MySQL\MySQL Server 8.0\bin>2020-10-01T13:06:32.497917Z 0 [System] [MY-010910] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Shutdown complete (mysqld 8.0.21) MySQL Community Server - GPL.
mysqld.exe --defaults-file="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\my.ini" --datadir="C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Data" --init-file=c:\\reset.txt --console
2020-10-01T13:06:36.133710Z 0 [Warning] [MY-000081] [Server] option 'read_buffer_size': unsigned value 614 adjusted to 8192.
2020-10-01T13:06:36.133802Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-10-01T13:06:36.135314Z 0 [System] [MY-010116] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe (mysqld 8.0.21) starting as process 9284
2020-10-01T13:06:36.149595Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-10-01T13:06:36.942139Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2020-10-01T13:06:37.269023Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060
2020-10-01T13:06:37.392127Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-10-01T13:06:37.392634Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2020-10-01T13:06:37.486710Z 0 [System] [MY-010931] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: ready for connections. Version: '8.0.21' socket: '' port: 3306 MySQL Community Server - GPL.
2020-10-01T13:06:53.165055Z 9 [Warning] [MY-013360] [Server] Plugin sha256_password reported: ''sha256_password' is deprecated and will be removed in a future release. Please use caching_sha2_password instead'
2020-10-01T13:06:59.761228Z 0 [System] [MY-013105] [Server] C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe: Normal shutdown.
Once the password reset is completed. You can go ahead and start the MySQL80
service.
get-service -Name mysql* | Start-Service
If you wish to stop service from services console, you can go to Start menu
, select Control Panel
, then Administrative Tools
, then Services
and start MySql80
service.