beego 使用连接mysql 报错 register db Ping `default1`, Error 1049: Unknown database 'test_beego' must have one register DataBase alias named `default
程序员文章站
2022-03-10 19:47:20
项目移植到另一台电脑后出现以下问题,及其解决方法: package models import ( "github.com/astaxie/beego/orm" _ "github.com/go-sql-driver/mysql" ) // User 用户表 type User struct { I ......
项目移植到另一台电脑后出现以下问题,及其解决方法:
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)
}
解决方法是 127.0.0.1换成localhost以后,就能成功运行并连接数据库了