Reset MySQL Password in WSL

visibility 524 event 2022-06-04 access_time 7 months ago language English
more_vert

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. 

copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts