且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从主机Windows连接到WSL MySQL

更新时间:2023-01-30 22:40:28

由于在

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';