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

x/website: MySQL config is incorrect in the database access tutorial. #49134

Open
kohkimakimoto opened this issue Oct 24, 2021 · 5 comments · May be fixed by golang/website#242
Open

x/website: MySQL config is incorrect in the database access tutorial. #49134

kohkimakimoto opened this issue Oct 24, 2021 · 5 comments · May be fixed by golang/website#242
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done. website

Comments

@kohkimakimoto
Copy link

MySQL config code should use AllowNativePasswords: true.
The tutorial https://golang.org/doc/tutorial/database-access describes MySQL config code as the following:

cfg := mysql.Config{
	User:   os.Getenv("DBUSER"),
	Passwd: os.Getenv("DBPASS"),
	Net:    "tcp",
	Addr:   "127.0.0.1:3306",
	DBName: "recordings",
}

But, it causes an error like the following:

[mysql] 2021/10/24 17:03:01 connector.go:95: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
2021/10/24 17:03:01 this user requires mysql native password authentication.

To run the code correctly, we should add AllowNativePasswords: true to the MySQL config or use msql.NewConfig method instead of creating mysql.Config struct directly. Please see the following full config code.

The correct code is:

cfg := mysql.Config{
	User:   os.Getenv("DBUSER"),
	Passwd: os.Getenv("DBPASS"),
	Net:    "tcp",
	Addr:   "127.0.0.1:3306",
	DBName: "recordings",
	AllowNativePasswords: true,
}

or

cfg := mysql.NewConfig()
cfg.User = os.Getenv("DBUSER")
cfg.Passwd = os.Getenv("DBPASS")
cfg.Net = "tcp"
cfg.Addr = "127.0.0.1:3306"
cfg.DBName = "recordings"

See also:

@gopherbot gopherbot added this to the Unreleased milestone Oct 24, 2021
@seankhliao seankhliao added NeedsFix The path to resolution is known, but the work has not been done. Documentation labels Oct 24, 2021
@seankhliao
Copy link
Member

maybe it should use mysql.NewConfig() to set defaults.

Also for doc/database/open-handle

cc @stevetraut

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/358294 mentions this issue: _content/doc: update mysql.Config to mysql.NewConfig

@thomas-cools
Copy link

This is still an issue unless I'm looking at an outdated version of this page: https://go.dev/doc/tutorial/database-access... I don't see the change to reference mysql.NewConfig, instead I still see

 cfg := mysql.Config{
        User:   os.Getenv("DBUSER"),
        Passwd: os.Getenv("DBPASS"),
        Net:    "tcp",
        Addr:   "127.0.0.1:3306",
        DBName: "recordings",
    }

@sprive
Copy link

sprive commented Aug 19, 2023

The Go MySQL tutorial fails without: AllowNativePasswords: true,
https://go.dev/doc/tutorial/database-access

@dr2chase or @eliben - Could you sponsor this doc change, or review with team?
https://github.com/golang/website/pull/242/checks

Please note during the 2 year window this issue is open, Go Twitter promoted it: https://twitter.com/golang/status/1641133293180420116

@eliben
Copy link
Member

eliben commented Aug 21, 2023

Thanks for bringing this to our attention, @sprive

I note that an earlier CL addressing this already exists in Gerrit: https://go-review.googlesource.com/c/website/+/358294 (it's mentioned here upthread). I will take a look at the CL and leave some comments - please help review it and update it, if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done. website
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants