How to connect to WSL mysql from Host Windows

帅比萌擦擦* 提交于 2020-01-12 10:10:32

问题


I am trying to connect HeidiSql from the host to my WSL Mysql but I could not get it to connect it

Error "can't connect to Mysql server on '127.0.0.1'"

Tried SSH too but could not connect to the server


回答1:


Since your question is asked before WSL2 release, So I assume you were using WSL1, for WSL1 you can access WSL1 MySQL directly from windows, but you were access in a wrong way, in the NetWork type, you should choose MariaDb or MySQL(TCP/IP) instead of MySQL (SSH Tunnel)

For WSL2 check this WSL github issue, save @edwindijas's powershell script and execute it by administrator, you may still can not access MySQL , and got access denied for user ... <you-computer-name>.mshome.net, you need to allow this user access it from this host, let's say root, you need execute this in mysql cli:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%<you-computer-name>.mshome.net' IDENTIFIED BY '<password>';

Or allow root user access WSL2 MySQL from any host:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';




回答2:


As for me who's also using WSL for making web based application

first make sure mysql is running on WSL like sudo service mysql start

then once started, open HeidiSql and simply connect to it, here the example on my part

make sure the IP address is 127.0.0.1 not any IP, not your IP used to connect on the internet



来源:https://stackoverflow.com/questions/54377052/how-to-connect-to-wsl-mysql-from-host-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!