Access MySQL from Host being on Vagrant

For this all you would need is tunneling/port forwarding from vagrant to mysql.

Being on vagrant machine, figure out what the host ip is, usually netstat would tell you that.
The default being and assuming you have 3306 port on host machine do the following

ssh username@ -L 3306: -N

The above would forward the 3306 [ the one on the left ] to the hosts port. Mind you, you have to use to access your vagrant machine in place of localhost which might not work.

Port not forwarded from vagrant for rails application on host

Having a rails application on the vagrant machine and the 3000 port not being forwarded when you access it form host machine like


if so keep reading

Assuming you have already setup your vagrant machine

Go ahead and open your Vagrant file, find the and update it with "forwarded_port", guest: 3000, host: 3000

Then make sure you are binding the server with as it is the main problem is being the default for that, when yoiu are instantiation the server do the binding with

bin/server --binding=

Basically the above would tell to listen to almost any ip. This has its own risk if you are doing it on public VM so caution shall be applied. Where as when it is, it will be listening to the local address only.


Connecting to Vagrant [PuPHPet] MySql from host

Probably here with – I can’t connect to mysql on vagrant machine Yup I have been there

If you are php developer and are using vagrant you would want to use mysql tool to access the vagrant mysql server.

Here is the step by step procedure.

I will assume the PuPHPet configuration
First, get the user which can connect from any host

Log into your vagrant

vagrant ssh

Then open the mysql configuration file

vi /etc/mysql/my.cnf

And update the bind-address part to be This will allow address to be used from any host.
If you want to specifically access from some host only, then put IP over there.

Then being in your vagrant machine run

mysql -uroot -p123

This will be depending on if you have provided a password for root the default on puPHPet would ask password so you would have a password

After this allow root user to access everything from everywhere.. or you can create another user and grant that

mysql > GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123';

Then to make the sql pickup the changes made so far

sudo service mysql restart

Then being on your host machine open your sequel pro – if you are on mac.. or other clients you would use for mysql.

Mysql Host:
Mysql user: root
Mysql Password: 123

SSH Host:
SSH Username: vagrant – this is the default one
SSH key -> point the key in puphpet/files/dot/ssh/id_rsa
SSH Port: 2222 – this is also the default ssh port forwarding, if you change this change it here too..

See how to Setting up vegrant machine from scratch here