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: Got an error with code in "Tutorial: Accessing a relational database" #50531

Closed
taroooth opened this issue Jan 10, 2022 · 1 comment

Comments

@taroooth
Copy link

What is the URL of the page with the issue?

page: https://go.dev/doc/tutorial/database-access

What is your user agent?

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36

Screenshot

スクリーンショット 2022-01-10 18 41 59

What did you do?

I wrote the code as per the documentation and ran it and got the following error.

% export DBUSER=username
% export DBPASS=password
% go run .
[mysql] 2022/01/10 17:16:10 connector.go:95: could not use requested auth plugin 'mysql_native_password': this user requires mysql native password authentication.
2022/01/10 17:16:10 this user requires mysql native password authentication.
exit status 1

I then rewrote the code using this issue as a reference. -> go-sql-driver/mysql#815 (comment)

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

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

And when I ran go run . again, this time I got the following error.

% go run .
2022/01/10 17:18:16 Error 1045: Access denied for user 'username'@'localhost' (using password: YES)
exit status 1

I found out that he did not have permission to the recordings database, so I granted him permission.

mysql> grant all on *.* to username@localhost;

I did the above and it worked.

% go run .
Connected!
Albums found: [{1 Blue Train John Coltrane 56.99} {2 Giant Steps John Coltrane 63.99}]
Album found: {2 Giant Steps John Coltrane 63.99}
ID of added album: 5

What did you expect to see?

I would like to see the following added to the documentation.

AllowNativePasswords: true,
@gopherbot gopherbot added this to the Unreleased milestone Jan 10, 2022
@seankhliao
Copy link
Member

Duplicate of #49134

@seankhliao seankhliao marked this as a duplicate of #49134 Jan 10, 2022
@golang golang locked and limited conversation to collaborators Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants