首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将MySQL工作台连接到WSL2

将MySQL工作台连接到WSL2
EN

Ask Ubuntu用户
提问于 2020-06-13 16:35:49
回答 2查看 27.6K关注 0票数 14

我有一个全新的WSL2,运行在最新的Windows10 (2004)上,带有Ubuntu20.04,安装了MySQL,我可以从Bash访问它并获得状态--

代码语言:javascript
复制
mysql> status
--------------
mysql  Ver 8.0.20-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))

Connection id:          10
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.20-0ubuntu0.20.04.1 (Ubuntu)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /var/run/mysqld/mysqld.sock
Binary data as:         Hexadecimal
Uptime:                 13 sec

接下来,我想连接MySQL工作台。我所得到的就是

代码语言:javascript
复制
Your connection failed for user 'root' to the MySQL server at 127.0.0.1:3306
Access denied for user 'root'@'localhost'

我的WSL2列表是--

代码语言:javascript
复制
PS C:\Users\gymdo> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

我的WSL2信息是--

代码语言:javascript
复制
Installation successful!
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.

Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.19.104-microsoft-standard x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  System information as of Sat Jun 13 02:35:32 EDT 2020

  System load:  1.97               Processes:             8
  Usage of /:   0.4% of 250.98GB   Users logged in:       0
  Memory usage: 0%                 IPv4 address for eth0: 172.20.109.28
  Swap usage:   0%

0 updates can be installed immediately.
0 of these updates are security updates.

我试过使用上面的172.20.109.28 --同样的错误

从Windows的角度看--

代码语言:javascript
复制
Ethernet adapter vEthernet (WSL):

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::c54a:f83c:a5f8:40b2%43
   IPv4 Address. . . . . . . . . . . : 172.20.96.1
   Subnet Mask . . . . . . . . . . . : 255.255.240.0
   Default Gateway . . . . . . . . . :

我试过使用上面的172.20.96.1 --同样的错误

奇怪的是--当我尝试root@localhost的用户名而不是简单的root时,工作台会弹出"enter password“弹出。我很兴奋,但当我将密码字段留为空白时,密码仍然失败:不。

我是个被打倒的人--我需要帮助。

EN

回答 2

Ask Ubuntu用户

发布于 2020-11-16 14:12:05

WSL2MySQLServer也有同样的问题;我通过用localhost替换工作台连接配置中的127.0.0.1来修复它。

127.0.0.1配置

Localhost配置

我希望它能对某人有用!

票数 8
EN

Ask Ubuntu用户

发布于 2021-01-25 17:57:08

问题在于如何对根用户进行身份验证。默认情况下,这是设置为使用auth_socket而不是mysql_native_password。

以root用户身份登录到wsl中的mysql服务器,并运行:

代码语言:javascript
复制
mysql > SELECT user, authentication_string, plugin, host FROM mysql.user;

输出将列出每个用户的身份验证方法。

现在使用以下命令更改根用户的方法:

代码语言:javascript
复制
mysql > ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

确保将根用户的“密码”更改为正确的密码。

现在运行命令来更新更改:

代码语言:javascript
复制
mysql > FLUSH PRIVILEGES;

现在再次运行该命令,以确保身份验证方法已更新:

代码语言:javascript
复制
mysql > SELECT user, authentication_string, plugin, host FROM mysql.user;

现在输出应该显示根用户的身份验证方法是使用mysql_native_password的。您现在应该能够以root用户的身份使用密码登录工作台。

票数 7
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1249973

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档