jkns.co
jkns.co

Reputation: 738

How to connect to Mysql VirtualBox Vagrant from another VirtualBox Vagrant?

I have two VirtualBox Vagrant machines running on my Mac:

  1. Ubuntu 16.04.1, private network: 192.168.122.13, running as a webserver (PHP, Apache, etc.).

  2. Ubuntu 16.04.1, private network: 192.168.122.14, running MySQL.

How do I connect to MySQL from the webserver?

I have enabled port forwarding on the MySQL box (3306 guest => 5629 host) and commented out the bind-address line in /etc/mysql/mysql.conf.d/mysqld.cnf. If I SSH onto the webserver and try to connect using mysql -host 192.168.122.14 -P 5629 -u xxx -p yyy the connection times out (ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.122.14' (110)).

Upvotes: 0

Views: 499

Answers (1)

tux
tux

Reputation: 1820

MySQL runs on the vagrant box with IP 192.168.122.14, and is listening on port 3306. When you forward ports, it means that the port 3306 from the virtual machine, is forwarded to your host OS on the port 5629.

From your web server (192.168.122.13) you could connect to mysql by

mysql -h 192.168.122.14 -P 3306 

or

mysql -h 192.168.122.1 -P 5629

Here 192.168.122.1, refers to the IP of your host OS. The IP 192.168.122.1 is created by vagrant and assigned to your host OS

Upvotes: 2

Related Questions