I created MySQL DB
and tried to connect to it from my go
application.
Here is a code:
`package users_db
import (
“database/sql”
“fmt”
“log”
_ "github.com/go-sql-driver/mysql"
)
var (
Client *sql.DB
)
func init() {
dataSourceName := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf-8",
“root”,
“root”,
“127.0.0.1”,
“users_db”,
)
var err error
Client, err = sql.Open("mysql", dataSourceName)
if err != nil {
panic(err)
}
if err = Client.Ping(); err != nil {
panic(err)
}
log.Println("Database successfully configured")
}
When I run go run main.go
terminal printed this:
panic: Error 1045: Access denied for user ‘root’@‘localhost’ (using password: YES)
goroutine 1 [running]:
github.com/arammikayelyan/bookstore_users-api/datasources/mysql/users_db.init.0()
/home/aram/go/src/github.com/arammikayelyan/bookstore_users-api/datasources/mysql/users_db/users_db.go:30 +0x1d7
exit status 2
How can I connect to the database which has a password?