Kontext Kontext | SQL Databases

Reset MySQL Password in WSL

event 2022-06-04 visibility 3,034 comment 0 insights toc
more_vert
insights Stats

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. 

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts