2018/06/07 16:16:14 INFO ▶ 0001 Using 'myapp' as 'appname'
2018/06/07 16:16:14 INFO ▶ 0002 Initializing watcher...
2018/06/07 16:16:38 SUCCESS ▶ 0003 Built Successfully!
2018/06/07 16:16:38 INFO ▶ 0004 Restarting 'myapp'...
2018/06/07 16:16:38 SUCCESS ▶ 0005 './myapp' is running...
[ORM]2018/06/07 16:16:38 register db Ping `default`, Error 1045: Access denied for user 'root'@'localhost' (using password: YES)
must have one register DataBase alias named `default`
网上查了好久没有的得到解决
能不能帮忙解决一下
<a href="/user/nickluo" title="@nickluo">@nickluo</a> 我以为用第三方驱动就好了,所有没有连数据库,出现这个错误。已经解决
#2
更多评论
应该是少加了注册默认的数据库,我这里有一个 beego 注册 mysql 的例子,你看看
const (
DEFAULT_DB = "default"
// 设置数据库 driver
MYSQL_DRIVER = "mysql"
)
func RegisterDB() error {
dbUser := beego.AppConfig.String("mysqluser")
dbPass := beego.AppConfig.String("mysqlpass")
dbHost := beego.AppConfig.String("mysqlhost")
dbPort := beego.AppConfig.String("mysqlport")
dbName := beego.AppConfig.String("mysqldb")
maxIdleConn, err := beego.AppConfig.Int("mysql_max_idle_conn")
if err != nil {
beego.Error("Mysql max idle conn is invalid: ", err)
return err
}
maxOpenConn, err := beego.AppConfig.Int("mysql_max_open_conn")
if err != nil {
beego.Error("Mysql max open conn is err: ", err)
return err
}
dbLink := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUser, dbPass, dbHost, dbPort, dbName) + "&loc=Asia%2FShanghai"
if beego.BConfig.RunMode == "dev" {
orm.Debug = true
}
// 注册驱动
err = orm.RegisterDriver(MYSQL_DRIVER, orm.DRMySQL)
if err != nil {
beego.Error("Orm register driver is err: ", err)
return err
}
// 注册数据库
err = orm.RegisterDataBase(DEFAULT_DB, MYSQL_DRIVER, dbLink, maxIdleConn, maxOpenConn)
if err != nil {
beego.Error("Orm register data base is err: ", err)
return err
}
// 注册表模型
orm.RegisterModel(new(YourTable))
// 自动建表
err = orm.RunSyncdb(DEFAULT_DB, false, true)
if err != nil {
beego.Error("Orm fun sync db is err: ", err)
return err
}
return nil
}
#1