Reset MySQL Password in WSL
When MySQL was installed on WSL (Install MySQL on WSL), by default, we can use command
sudo mysql to start MySQL CLI without the need to input the password.
Reset root user password
Run the following command to start mysql CLI:
And then run the following SQL statement to change password:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root';
The above statement changes password to 'root'.
Reset other user's password
Similarly, run the following command to change other user's password:
mysql> ALTER USER 'user'@'localhost' IDENTIFIED BY 'newpassword';
Reset root password using init file
mysql-init' in user home folder with the following statement:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
And then stop or kill
mysqld and run the following command:
sudo mysqld --init-file=/home/username/mysql-init &
Remember to change the file path accordingly.