I had the same problem with WSL 2 MySQL-Server; I fixed it by replacing 127.0.0.1 in the config of workbench connection with localhost.

127.0.0.1 config

Failed to connect error with Hostname: 127.0.0.1

Localhost config

successful connection with Hostname: localhost

I hope it will be useful for someone!


After some more searching I found hints that I may need to GRANT access. From inside the WSL2 box I added a new user and GRANTed access.

mysql> CREATE USER 'newguy'@'localhost' IDENTIFIED BY 'ratfink';
Query OK, 0 rows affected (0.02 sec)

mysql> GRANT ALL ON mysql.* TO 'newguy'@'localhost';
Query OK, 0 rows affected (0.01 sec)

Check the examples down the page here.

I am now able to connect via MySQL Workbench with user: newguy and password: ratfink from MySQL Workbench. I have not been able to GRANT access to root. I even tried removing root as a user and re-adding root without success. Shouldn't mess with Mother Nature I guess.


The problem is how the root user is authenticated. By default this is set to use auth_socket instead of mysql_native_password.

Log into the mysql server in wsl as root user and run:

mysql > SELECT user, authentication_string, plugin, host FROM mysql.user;

The output will list the authentication method for each user.

Now change the method for the root user with the following command:

mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Make sure to change 'password' to the correct password for the root user.

Now run command to update changes:

mysql > FLUSH PRIVILEGES;

Now run the command again to make sure the authentication method updated:

mysql > SELECT user, authentication_string, plugin, host FROM mysql.user;

Now the output should show that the authentication method for the root user is with mysql_native_password. You should now be able to log into workbench as root user using the password.