Skip to content

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

Closed as not planned
@Omkar0114

Description

@Omkar0114

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions