Connect to mysql db from go

I created MySQL DB and tried to connect to it from my go application.

Here is a code:

`package users_db

import (

_ ""


var (
Client *sql.DB

func init() {
dataSourceName := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf-8",
var err error

Client, err = sql.Open("mysql", dataSourceName)
if err != nil {

if err = Client.Ping(); err != nil {

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]:
/home/aram/go/src/ +0x1d7
exit status 2

How can I connect to the database which has a password?

Make sure the user has permissions to the schema, please don’t use root as login. Here is a good how to