Can only connect to a mysql running in a docker container when "allowPublicKeyRetrieval=true" in DBeaver driver settings

huangapple go评论91阅读模式
英文:

Can only connect to a mysql running in a docker container when "allowPublicKeyRetrieval=true" in DBeaver driver settings

问题

我正在使用一个Docker容器在我的主机上运行一个MySQL服务器,用于本地开发一个Golang应用程序。问题是,我尝试使用各种客户端连接它时,总是能够成功连接,但在运行查询时返回错误。例如,在VSCode的SQLTools中:

请求连接/获取树项的子项请求失败,错误信息为:
ER_NOT_SUPPORTED_AUTH_MODE: 客户端不支持服务器请求的身份验证协议;请考虑升级MySQL客户端

当我尝试使用Golang连接时,我得到以下错误:

go run ./cmd/web
ERROR 2021/12/16 04:28:55 main.go:32: 错误 1045: 用户'web'@'172.18.0.1'被拒绝访问(使用密码:YES)
退出状态 1

(Golang数据源为"user:pass@/database?parseTime=true",使用mysql驱动程序)

然而,DBeaver能够成功连接,但如果我尝试在不更改任何设置的情况下连接,会收到以下消息:

连接错误:
不允许公钥检索

因此,进入驱动程序设置,并将"allowPublicKeyRetrieval"从"false"更改为"true"将使一切正常工作。

是否有办法使用Golang驱动程序允许"公钥检索"?是否有什么我可以从MySQL控制台更改,以避免这种情况?我在文档中找不到任何信息(https://github.com/go-sql-driver/mysql),在找到成功连接的方法之前,我无法继续进行我的项目。

英文:

I am using a docker container to run a mysql server for local developement of a golang application from my host machine, the problem is,I have tried to connect to it using various clients and it always connects successfully, but returns errors when running queries, for example in sqltools for vscode:

Request connection/GetChildrenForTreeItemRequest failed with message: 
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; 
consider upgrading MySQL client

When I try to connect with golang I get:

go run ./cmd/web
ERROR	2021/12/16 04:28:55 main.go:32: Error 1045: Access denied for user 'web'@'172.18.0.1' (using password: YES)
exit status 1

(Golang data source is "user:pass@/database?parseTime=true" using the mysql driver)

DBeaver however, is able to connect succesfully, but if I try to do it without changing any settings, I get the following message:

Connection error:
Public Key Retrieval is not allowed

So, going to driver settings and changing "allowPublicKeyRetrieval" from "false" to "true" will make everything work fine.

Is there any way to allow this "public key retrieval" using the golang driver? Is there something I can change from the mysql console so this is not needed? I couldn't see anything in the documentation ( https://github.com/go-sql-driver/mysql ) and I can't continue with my project until I figure out a way to connect it successfully Can only connect to a mysql running in a docker container when "allowPublicKeyRetrieval=true" in DBeaver driver settings

答案1

得分: 1

首先,请检查是否只需在JDBC查询中添加?allowPublicKeyRetrieval=true

检查一下你如何启动Mysql的Docker镜像,确保你公开了端口。并尝试使用Mysql一开始生成的root账户/密码(如此处所示)。一旦这个可以工作,你可以检查web用户。

英文:

Check first, as in here, if adding ?allowPublicKeyRetrieval=true to your JDBC query is enough.

Check how you launch your Mysql docker image, make sure you public your ports.
Ad try using the root account/password generated by Mysql at the very beginningn as shown here.
Once that is working, you can check for the web user.

答案2

得分: 1

我想你可能已经弄清楚了,但以防万一,这是我的答案。

你似乎在按照《Let's Go》这本书的指导进行操作(我也在用这本书)。书中的指令是使用CREATE USER 'web'@'localhost';来创建一个用户。如果你看一下错误信息Error 1045: Access denied for user 'web'@'172.18.0.1'...,它告诉你正在尝试连接到172.18.0.1而不是localhost

修复这个问题最简单的方法是使用CREATE USER 'web'@'%';来创建用户,其中%表示允许从任何地方进行连接。

英文:

I think you might have figured it out already, but in case you don't here's my answer.

You seem to be following the "Let's Go" book (I am). The instruction in the book is to create a user with CREATE USER 'web'@'localhost';. If you take a look at the error Error 1045: Access denied for user 'web'@'172.18.0.1'... it's telling you that is trying to connect at 172.18.0.1 rather than localhost.

The easiest way to fix this, is to create the user with CREATE USER 'web'@'%'; where % means that it would allow connections from anywhere.

huangapple
  • 本文由 发表于 2021年12月16日 12:41:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/70373900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定