Reputation:
I am running Windows 10 Build 1904.1706 and Ubuntu 20.04 through WSL2 version 5.10.16.3-microsoft-standard-WSL2.
I am trying to install mysql (something I have done plenty of times before on regular linux machines) and I am running into some issues logging into MySQL using both the root account and a user I have created.
When I try to connect to the database using mysql -u root -p
OR mysql -u root
, I am given the following error:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (13)
I have ruled out it being me connecting from the wrong host, since I have run an ALTER USER
command to change root's host from 'localhost' to '%'. I get the same error when connecting as the user account I've created.
However, I can connect fine if I prepend mysql -u root -p
with sudo
.
Finally I have also tried to modify /etc/mysql/mysqld.conf.d/mysqld.cnf
and changed the bind-address
field to 0.0.0.0
and that made no change in behavior.
On all of my other MySQL installations I have experience with, I never need to use sudo
to log into mysql as a valid user, so I am wondering if WSL2 is playing a role.
Edit: To add, when I am trying to connect to my MySQL server, I am doing so from within the WSL terminal and NOT a Windows terminal like Powershell.
I saw another StackOverflow thread that suggested to CHMOD the /var/lib/mysql
directory recursively, but that made no difference as well
Upvotes: 0
Views: 2416
Reputation:
For anyone else with this issue, you can connect to MySQL without sudo by appending the --protocol=tcp
flag to your mysql command.
Ex. mysql -u root -p --protocol=tcp
Upvotes: 4