allowCleartextPasswords = 1到DSN

I'm attempting to connect to my local DB via a mysql connection to initiate and run a query off of my database via Go.

When attempting to connect, I am met with this error:

this user requires clear text authentication. If you still want to use it, please add allowCleartextPasswords=1' to your DSN

My Db connection looks like the following: db, err := sql.Open("sql", "<username>:<password>@tcp(127.0.0.1:<port>)/<dbname>?charset=utf8" )

Where can I include this dependency for cleartext authentication?

Since you mentioned you're using MySQL I recommend leveraging the native struct mysql.Config like so:

loc, _ := time.LoadLocation("America/Chicago") // handle any errors!

c := mysql.Config{
    User:                    "user",
    Passwd:                  "pa55w0rd",
    Net:                     "tcp",
    Addr:                    "127.0.0.1:3306",
    DBName:                  "dbname",
    Params:                  map[string]string{"charset": "utf8"}, // extra params
    AllowCleartextPasswords: true,
    ParseTime:               true, // demo option
    Loc:                     loc,  // demo option
}
fmt.Println(c.FormatDSN())

It will properly format the DSN string for you - escaping any sensitive character values along the way (e.g. the loc value):

user:pa55w0rd@tcp(127.0.0.1:3306)/dbname?allowCleartextPasswords=true&allowNativePasswords=false&loc=America%2FChicago&parseTime=true&maxAllowedPacket=0&charset=utf8

Playground Example