Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect to mysql server 8.0 when password is larger than 19 characters #911

Closed
erfanium opened this issue Aug 30, 2024 · 7 comments · Fixed by #914
Closed

Can't connect to mysql server 8.0 when password is larger than 19 characters #911

erfanium opened this issue Aug 30, 2024 · 7 comments · Fixed by #914

Comments

@erfanium
Copy link

erfanium commented Aug 30, 2024

Affected version: 1.8.0
Latest working version: 1.7.0

Reproduction Steps

1- mysql server with complex password and caching_sha2_password as default

services:
  mysql_test:
    image: mysql:8.0.33
    environment:
      MYSQL_ROOT_PASSWORD: "*pl3$#&XiC4Tn*AP13l#OKUY"
      MYSQL_DATABASE: default
      MYSQL_USER: base-user
      MYSQL_PASSWORD: "*pl3$#&XiC4Tn*AP13l#OKUY"
    ports:
      - "3306:3306"
    command: --default-authentication-plugin=caching_sha2_password

2-

package main

import "github.com/go-mysql-org/go-mysql/client"

func main() {
	conn, err := client.Connect("127.0.0.1:3306", "root", "*pl3$#&XiC4Tn*AP13l#OKUY", "default")
	if err != nil {
		panic(err)
	}
	defer conn.Close()

	_, err = conn.Execute(`select 1;`)

	if err != nil {
		panic(err)
	}

	println("connected")
}

then you will see this error:

panic: handleAuthResult: ERROR 1045 (28000): Access denied for user 'root'@'172.23.0.1' (using password: YES)
@lance6716
Copy link
Collaborator

Thank for reporting, I'll take a look next week

@erfanium
Copy link
Author

@lance6716
Thanks! I'm new to golang, but I can contribute on this if you need.

@lance6716
Copy link
Collaborator

@erfanium Thank you, currently I only tried to reproduce this problem, but I have not started to locate the root cause. This is my testing steps:

docker run --rm --name mysql-3306 -p 3306:3306 -e MYSQL_ROOT_PASSWORD='*pl3$#&XiC4Tn*AP13l#OKUY' mysql:8.0.33 --log-bin=mysql-bin --port=3306 --bind-address=0.0.0.0 --binlog-format=ROW --server-id=1 --gtid_mode=ON --enforce-gtid-consistency=true --default-authentication-plugin=caching_sha2_password

then add this unit test in client package

func TestComplexPassword(t *testing.T) {
	conn, err := Connect("127.0.0.1:3306", "root", "*pl3$#&XiC4Tn*AP13l#OKUY", "default")
	require.NoError(t, err)
	defer conn.Close()

	_, err = conn.Execute(`select 1;`)
	require.NoError(t, err)
}

I think you can help me in many aspects, like fixing the code, adding unit tests in our CI, using git bisect to find the commit that caused the problem. I'll start to do rest work after you choose some.

@erfanium
Copy link
Author

erfanium commented Sep 6, 2024

So far I have figured out that it's not about spacial characters. any password larger than 19 characters is not working! So it's kinda a critical bug.

sample not working password: abcdefghijklmnopqrsu

@erfanium erfanium changed the title Can't connect to mysql server when password with special characters has been used Can't connect to mysql server when password is larger than 19 characters Sep 6, 2024
@erfanium
Copy link
Author

erfanium commented Sep 6, 2024

I'll start to do rest work after you choose some

I have spent many hours working on this issue, but it requires a good knowledge of mysql auth mechanism. so I might not be able to fix it very soon.

@lance6716
Copy link
Collaborator

Thanks, that's very helpful. I'll take a look soon

@lance6716
Copy link
Collaborator

136935a is the first bad commit

@lance6716 lance6716 changed the title Can't connect to mysql server when password is larger than 19 characters Can't connect to mysql server 8.0 when password is larger than 19 characters Sep 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants