Reset MySQL Password in WSL

Kontext Kontext 0 3784 3.37 index 6/4/2022

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:

sudo mysql

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

Another approach is to created a init file named '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.

mysql wsl

Join the Discussion

View or add your thoughts below

Comments