如何从主机Windows连接到WSL MySQL [英] How to connect to WSL mysql from Host Windows
问题描述
我正在尝试将HeidiSql从主机连接到我的WSL Mysql,但是我无法通过它进行连接
I am trying to connect HeidiSql from the host to my WSL Mysql but I could not get it to connect it
错误无法连接到'127.0.0.1'上的Mysql服务器"
Error "can't connect to Mysql server on '127.0.0.1'"
也尝试过SSH,但无法连接到服务器
Tried SSH too but could not connect to the server
推荐答案
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)
对于WSL2,请检查 WSL github问题,保存@edwindijas的powershell脚本并执行由管理员执行,您可能仍然无法访问MySQL,并获得access denied for user ... <you-computer-name>.mshome.net
,您需要允许该用户从此host
访问它,比方说root,您需要在mysql cli中执行此操作:
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>';
或允许root用户从任何主机访问WSL2 MySQL:
Or allow root user access WSL2 MySQL from any host:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
这篇关于如何从主机Windows连接到WSL MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!