beego 使用连接mysql 报错 register db Ping `default1`, Error 1049: Unknown database 'test_beego' must have one register DataBase alias named `default`

The following problems after transplant project to another computer, and their solutions:

package models

import (
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
)

// User 用户表
type User struct {
	ID       int
	UserName string
	Password string
}

func init() {
	orm.RegisterDataBase("default", "mysql", "root:root@tcp(127.0.0.1:3306)/test_beego?charset=utf8")
	orm.RegisterModel(new(User))
	orm.RunSyncdb("default", false, true)
}

 The solution is to be replaced after 127.0.0.1 localhost, and will be able to successfully run the database connection

Guess you like

Origin www.cnblogs.com/Mishell/p/12162194.html