I set up MySQL on Windows Subsystem for Linux (WSL2 version). I'm relatively new to MySQL, but I have confirmed the following:
ps ax | grep mysqld
returns a value)127.0.0.1
3306
To login to the mysql shell, I use the command sudo mysql -u root -p
. Without sudo, I am unable to login to the shell.
I assume that this issue has something to do with the host that the MySQL service is running on, but I have no idea how to change that and properly connect. Below is a screenshot of the connection setup in MySQL Workbench.
And below is the error that I get when I use the settings shown and my root
user password.
normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
Check that MySQL is running on address localhost. Check that MySQL is reachable on port 3306 (note: 3306 is the default, but this can be changed). Check the user root has rights to connect to localhost from your address (MySQL rights define what clients can connect to the server and from which machines).
Turns out, this had nothing to do with WSL at all, but rather the authentication method for the MySQL user.
As of MySQL version 5.5.10, users have the ability to use auth_socket authentication. In my case, I used the Linux apt
repository to configure and install MySQL, and this was set as the default authentication method, as shown by the output of the following command:
SELECT user,authentication_string,plugin,host FROM mysql.user;
MySQL Workbench does not support this type of authentication, and therefore, you must revert back to the old method of authentication, mysql_native_password
.
To do this, run the following command while logged in as root
, or whatever user you are trying to connect to MySQL Workbench with:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';
After doing that, MySQL workbench connects fine.
I have had issues connecting to Mysql running in WSL2 at first but I am now able to connect to the WSL2 MySQL instance via localhost. You just have to make sure that MySQL is listening on all ports which it does by default in MySQL 8.
[mysql]
port=3307 # or any port you like
bind-address=0.0.0.0
[
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With