首先要获取宿主机(Windows)的IP:

export HOST_IP=$(grep -oP '(?<=nameserver\ ).*' /etc/resolv.conf)

然后通过-h指定MySQL服务器所在的IP访问:

mysql -h $HOST_IP -uroot -proot

可能会出现以下错误:

Host is not allowed to connect to this MySQL server.

这是因为MySQL默认禁用远程访问,解决方法:

# 用Windows登录MySQL,然后执行以下语句
use mysql;
update user set host = '%' where user = 'root';
FLUSH PRIVILEGES; # 必须执行这一步,否则无效

参考
Host is not allowed to connect to this MySQL server解决方法_写代码的林克-CSDN博客

相关文章:

  • 2022-12-23
  • 2022-01-04
  • 2021-07-11
  • 2022-12-23
  • 2022-01-14
  • 2021-06-14
猜你喜欢
  • 2021-05-23
  • 2022-12-23
  • 2021-08-29
  • 2022-01-22
  • 2021-11-29
  • 2021-10-08
相关资源
相似解决方案