【问题标题】:How to connect to Mysql VirtualBox Vagrant from another VirtualBox Vagrant?如何从另一个 VirtualBox Vagrant 连接到 Mysql VirtualBox Vagrant?
【发布时间】:2017-05-20 15:10:03
【问题描述】:

我的 Mac 上运行了两台 VirtualBox Vagrant 机器:

  1. Ubuntu 16.04.1,专用网络:192.168.122.13,作为网络服务器(PHP、Apache 等)运行。

  2. Ubuntu 16.04.1,专用网络:192.168.122.14,运行 MySQL。

如何从网络服务器连接到 MySQL?

我在 MySQL 机器上启用了端口转发(3306 来宾 => 5629 主机)并注释掉了 /etc/mysql/mysql.conf.d/mysqld.cnf 中的 bind-address 行。如果我通过 SSH 连接到网络服务器并尝试使用 mysql -host 192.168.122.14 -P 5629 -u xxx -p yyy 连接,则连接超时 (ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.122.14' (110))。

【问题讨论】:

    标签: vagrant virtualbox


    【解决方案1】:

    MySQL 运行在 IP 为 192.168.122.14 的 vagrant box 上,并且正在监听 3306 端口。当你转发端口时,意味着来自虚拟机的 3306 端口被转发到你的主机操作系统的 5629 端口。

    您可以从您的网络服务器 (192.168.122.13) 通过

    连接到 mysql
    mysql -h 192.168.122.14 -P 3306 
    
    or
    
    mysql -h 192.168.122.1 -P 5629
    

    这里的 192.168.122.1,指的是你的主机操作系统的 IP。 IP 192.168.122.1 由 vagrant 创建并分配给您的主机操作系统

    【讨论】:

    • 那行得通。非常感谢@deepak。我以为我试过了,但显然没有!
    • 您可以使用操作系统的 IP,例如 localhost,或者更好的 127.0.0.1:forwarded_to_port 或 Ip_of_the_vagrant_machine:forwarded_from_port
    猜你喜欢
    • 2016-09-11
    • 2019-04-26
    • 2016-10-16
    • 2013-11-24
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 2016-03-30
    • 2015-08-12
    相关资源
    最近更新 更多