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: Tutorial Code: Error while connecting the MYSQL database. #59832

Closed
Omkar0114 opened this issue Apr 25, 2023 · 2 comments
Closed

x/website: Tutorial Code: Error while connecting the MYSQL database. #59832

Omkar0114 opened this issue Apr 25, 2023 · 2 comments

Comments

@Omkar0114
Copy link

What is the URL of the page with the issue?

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

What is your user agent?

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36

Screenshot

image

What did you do?

I am following this Tutorial: Accessing a rational database
In the first place when we try to run the main.go to file with the below code

var db *sql.DB

func main() {
    // Capture connection properties.
    cfg := mysql.Config{
        User:   os.Getenv("DBUSER"),
        Passwd: os.Getenv("DBPASS"),
        Net:    "tcp",
        Addr:   "127.0.0.1:3306",
        DBName: "recordings",
    }
    // Get a database handle.
    var err error
    db, err = sql.Open("mysql", cfg.FormatDSN())
    if err != nil {
        log.Fatal(err)
    }

    pingErr := db.Ping()
    if pingErr != nil {
        log.Fatal(pingErr)
    }
    fmt.Println("Connected!")
}

many folks getting error when main.go file execute. the error getting is : This user requires MySQL native password authentication.

image

What did you expect to see?

I expect to see the MySQL database is connected with the Go code.

What did you see instead?

Instead of a connected database, I am getting this user requires MySQL native password authentication. this error and database connection is refused when we run main.go file.

@gopherbot gopherbot added this to the Unreleased milestone Apr 25, 2023
@Omkar0114
Copy link
Author

I tried to resolve this error, in config code below

cfg := mysql.Config{
        User:                 "root",
        Passwd:               "",
        Net:                  "tcp",
        Addr:                 "127.0.0.1:3306",
        DBName:               "recordings",
    }

If we add one more value AllowNativePasswords: true in the config code
the MySQL database is connecting.
Final code looks like this:

   cfg := mysql.Config{
        User:                 "root",
        Passwd:               "",
        Net:                  "tcp",
        Addr:                 "127.0.0.1:3306",
        DBName:               "recordings",
        AllowNativePasswords: true,
    }

@seankhliao
Copy link
Member

Duplicate of #49134

@seankhliao seankhliao marked this as a duplicate of #49134 Apr 25, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2023
@golang golang locked and limited conversation to collaborators Apr 24, 2024
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