Skip to content

mysql5.7 unknown auth plugin #815

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

Closed
gocuntian opened this issue Jun 6, 2018 · 21 comments
Closed

mysql5.7 unknown auth plugin #815

gocuntian opened this issue Jun 6, 2018 · 21 comments
Assignees
Labels
Milestone

Comments

@gocuntian
Copy link

gocuntian commented Jun 6, 2018

Issue description

Tell us what should happen and what happens instead
mysql5.7 unknown auth plugin

Example code

// version go1.10.2 darwin/amd64
db, err := sql.Open("mysql", "admin:admin@tcp(127.0.0.1:9696)/test")
	if err != nil {
		fmt.Println("failed to open database:", err.Error())
		return
	}
	defer db.Close()

	rows, err := db.Query("SELECT id,str FROM test_shard_hash")
	if err != nil {
		fmt.Println("fetech data failed:", err.Error())
		return
	}
	defer rows.Close()
	for rows.Next() {
		var id int
		var str string
		rows.Scan(&id, &str)
		fmt.Println("uid:", id, "name:", str)
	}

Error log

[mysql] 2018/06/06 22:15:07 auth.go:293: unknown auth plugin:
[mysql] 2018/06/06 22:15:07 driver.go:120: could not use requested auth plugin '': this authentication plugin is not supported

Configuration

  • Driver version (or git SHA): origin/master

  • Go version:go1.10.2 darwin/amd64

  • Server version:MySQL 5.7

  • Server OS: macOS 10.13.4 (17E202)

@gocuntian gocuntian changed the title mysql5.7 mysql5.7 unknown auth plugin Jun 6, 2018
@julienschmidt
Copy link
Member

The following section is also for a good reason in the issue template:

### Configuration
*Driver version (or git SHA):*

*Go version:* run `go version` in your console

*Server version:* E.g. MySQL 5.6, MariaDB 10.0.20

*Server OS:* E.g. Debian 8.1 (Jessie), Windows 10

@julienschmidt
Copy link
Member

My guess is that your master branch is not the latest version. Please check the specific version with git rev-parse HEAD and sync and try again with the newer version if necessary.

@xinzongyan
Copy link

hello,I also have this problem. Do you have resolved?

@gocuntian
Copy link
Author

no

@julienschmidt
Copy link
Member

Does this branch fix the issue for you? https://github.com/go-sql-driver/mysql/tree/empty_auth

@julienschmidt
Copy link
Member

julienschmidt commented Jun 11, 2018

In any case, it would be great if you could insert a simple print(data) after this block

mysql/packets.go

Lines 157 to 167 in d523deb

func (mc *mysqlConn) readHandshakePacket() ([]byte, string, error) {
data, err := mc.readPacket()
if err != nil {
// for init we can rewrite this to ErrBadConn for sql.Driver to retry, since
// in connection initialization we don't risk retrying non-idempotent actions.
if err == ErrInvalidConn {
return nil, "", driver.ErrBadConn
}
return nil, "", err
}
and here

mysql/packets.go

Lines 469 to 474 in d523deb

func (mc *mysqlConn) readAuthResult() ([]byte, string, error) {
data, err := mc.readPacket()
if err != nil {
return nil, "", err
}
and send us the resulting packet dump so that we can use it to create a regression test.

@julienschmidt
Copy link
Member

@gocuntian did you resolve the problem?

@Sharethings
Copy link

I have the same question, my question is my server send the init packet without the way of auth
accroding source code:
auth.go:240, in func auth(), add the code:
if plugin == "" {
plugin = "mysql_native_password"
}
my problem have been solved

@alpicola
Copy link

I got the same warning when connecting to MySQL 5.1.

auth.go:293: unknown auth plugin:
driver.go:120: could not use requested auth plugin '': this authentication plugin is not supported

The branch https://github.com/go-sql-driver/mysql/tree/empty_auth fixed it. Do you have a plan to merge the branch? @julienschmidt

@mbertschler
Copy link

mbertschler commented Jul 2, 2018

I have the same problem.
driver.go:113: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
Fails on master (go get)
Fails with v1.4.0
Works with v1.3.0

I could provide more info if you need it. Or do you think that is another problem and I should create a new issue?

@julienschmidt
Copy link
Member

Reopened. See #828 and #835 (PR for empty_auth branch)

@julienschmidt julienschmidt added this to the v1.4.1 milestone Jul 13, 2018
@julienschmidt julienschmidt self-assigned this Jul 13, 2018
@kwoodhouse93
Copy link
Contributor

kwoodhouse93 commented Jul 13, 2018

I just want to highlight that there seem to be two problems here with very similar symptoms.

The fix in #835 appears to fix the case where there's an empty auth plugin name, but it doesn't solve the issue @mbertschler and I had with the mysql_native_password plugin (see #828 (comment) for further details).

Maybe that's a different issue, but I suspect a wider fix is required than that proposed in #835.

@julienschmidt
Copy link
Member

@kwoodhouse93 Can you send us a packet log, e.g. as described here: #815 (comment) (preferably using the empty_auth branch / #835)?

@julienschmidt
Copy link
Member

And also try adding &allowNativaPasswords=true to your DSN, just in case (it should be true by default)

@kwoodhouse93
Copy link
Contributor

Using empty_auth branch, I added print(data) in the places mentioned, and the output was:

[74/4092]0xc42036c004[mysql] 2018/07/13 11:49:18 driver.go:123: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
[74/4092]0xc420371004[mysql] 2018/07/13 11:49:26 driver.go:123: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
...

That repeated 12 times before it stopped retrying, each with a slightly different address.

Regarding my DSN, I'm using mysql.Config with FormatDSN(). AllowNativePasswords was omitted when creating the Config struct, so I added AllowNativePasswords: true,. That changed the behaviour somewhat, but ultimately still returned the same error.

[74/4092]0xc420294004[7/4092]0xc420294004S[74/4092]0xc4201bb004[mysql] 2018/07/13 11:53:13 driver.go:123: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.

(Note, it didn't repeat this time. It just failed once and returned an error to my client app)

Looking at the output produced by print(data), were you hoping to see the contents of those addresses? Happy to try again if you can tell me how to get at it (would look myself, but I don't have much more time to spend on this today).

@mglonnro
Copy link

I upgraded and got this error:

could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.

I'm using the proxy dialer with DialCfg from github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/mysql, and in my case the simple fix was to add AllowNativePasswords in the config struct.

&mysqldriver.Config{ AllowNativePasswords: true, ... }

@julienschmidt
Copy link
Member

@mglonnro see #815 (comment)

@john8329
Copy link

This error was solved in my case by specifying AllowNativePasswords: true in the configuration

@methane
Copy link
Member

methane commented Oct 23, 2018

AllowNativePassword is true by default.
You shouldn't use Config{} to create config object. Use DSN or NewConfig().

https://godoc.org/github.com/go-sql-driver/mysql#Config

If a new Config is created instead of being parsed from a DSN string, the NewConfig function should be used, which sets default values.

@john8329
Copy link

Thanks. I was creating a Config because I read in the API docs, missed that step.

@bb-tb-navneet
Copy link

This error was solved in my case by specifying AllowNativePasswords: true in the configuration

this worked in my case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests