skip to Main Content

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 🙁

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search