MySQL远程登录的设置

在云平台上安装了MySQL docker环境后,需要进行远程登录的设置。MySQL镜像为8.0(8.0以下的设置有一些区别),数据库用户为root。
mysql -u root -p (输入初始密码登录123456)
create user root@‘%’ identified by ‘cloudSpring091845@#’;
grant all privileges on . to root@‘%’ with grant option;
flush privileges;
这个时候在客户端填充对应的host公网IP地址、root和password(cloudSpring091845@#)就可以进行访问了。
现在存在一个问题,就是你在云主机的shell上,会出现:
mysql -u root -p 是旧密码(123456)
mysql -u localhost - u root -p 是旧密码(123456)
mysql -u 127.0.01 -u root -p是新密码(cloudSpring091845@#)
mysql -u 内网IP地址 -u root -p是新密码(cloudSpring091845@#)
mysql -u 外网IP地址 -u root -p是新密码(cloudSpring091845@#)

select host, user, authentication_string from user;
会发现root对应两个用户%和localhost,且authentication_string不一样。

这个时候可以通过sql修改localhost/root对应的authentication_string,修改后
使用mysql -u root -p就可以使用新密码登录了,与其他的保持一致。

但是存在一个问题(原因不明),select host, user, authentication_string from user;
看到的密码仍然不一样,虽然localhost能用相同的新密码登录,重启主机和服务也不行。

解决方式如下:
//root用户(数据库用户)对应的密码置为空
update user set authentication_string=‘’ where user=‘root’;
//localhost(访问数据库的主机)
alter user root@‘localhost’ identified with mysql_native_password by ‘cloudSpring091845@#’;
//% (访问数据库的任意主机,不包括localhost)
alter user root@‘%’ identified with mysql_native_password by ‘cloudSpring091845@#’;
flush privileges;
做完后,得到结果:
能远程登录
本地shell的localhost能用新密码登录
在数据库中查看,localhost与%的authentication_string相同。
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

遥望山顶的小孩

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值