最近,踩坑云服务器通过root用户远程连接Mysql数据库失败,Mysql 版本为 5.7.44,原因如下,因为root用户权限过大,可能会有风险操作,可以新增其他用户来解决此问题,如果一定要用root用户,必须给其设置密码并且赋予远程访问权限
启动数据库
systemctl start mysql
连接数据库,空密码
mysql -u root -p
查看数据库用户列表
use mysql;
select user,host from user;

localhost代表只能本地访问,%代表无限制访问
修改 root 密码,权限,5.7版本之后的密码为authentication_string
update user set host = '%' where user = 'root';
update user set authentication_string=PASSWORD('new_password') where user = 'root';
刷新
flush privileges
重启数据库
systemctl restart mysql
测试下连接数据库
db.config.yaml
db:
user: root
password: '******'
host: 49.232.141

最低0.47元/天 解锁文章
605

被折叠的 条评论
为什么被折叠?



