【solved】must have one register DataBase alias named `default`
作者:互联网
beego在初始化MySQL数据库时报错处理
1.报错提示:
...
[ORM]2019/10/11 08:42:52 register db Ping `default`, dial tcp 192.168.xxx.xxx:3306: connect: connection refused
...
must have one register DataBase alias named `default`
2.beego初始化mysql代码:
// init 初始化 func init() { orm.RegisterDataBase("default", "mysql", "username:password@tcp(192.168.xxx.xxx:3306)/xxxdb?charset=utf8", 30) orm.RegisterModel(new(Course)) }
运行环境:Ubuntu server 19.04
3.排除代码错误以外,还应该注意:
在安装MySQL之后,其默认是链接本地 localhost 127.0.0.1;
创建数据库用户名时需要修改权限,给予数据表赋予权限,还应该修改以下文件:
/etc/mysql/mysql.conf.d/mysqld.cnf
操作步骤:
1. sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
2.找到bind-address,注释掉此行,【默认绑定的是127.0.0.1】,保存退出
#bind-address = 127.0.0.1
3.执行:
sudo source mysql restart
4.完成以上步骤方可初始化mysql
-------------------------如有其他问题的小伙伴可以贴出来一起讨论,并解决..........................................
标签:初始化,named,127.0,DataBase,default,0.1,xxx,solved,mysql 来源: https://www.cnblogs.com/LazyAngel/p/11656762.html