It's possible to connect to the Host's MySQL Server inside a Vagrant box? I'm running a RoR vagrant box, but I need to connect to the host database server.
Any help?
* You can enter your MySQL shell by entering mysql -u root -p in your Vagrant shell. Note that I’m allowing the root user to be able to login from any host now. Everything in this post is meant for local development and should NOT be done on a live server.
This gist shows how to connect to your vagrant MySQL database from the host machine. Change parameter bind-address to 0.0.0.0 to allow all incoming connection attempts On host connect as root user using mysql -uroot -proot Insert GRANT ALL PRIVILEGES ON *.*
First thing you need to do is forward the default MySQL port (3306) on your virtual box / Vagrant machine. You can do so by editing your Vagrantfile and add the following code: config.vm.network "forwarded_port", guest: 3306, host: 3306
Make sure you remove any public keys from your host machine's known_hosts file that are for the same host (IP Address). This will have happened if you have been using another Vagrant VM with the same IP address You can also get the SSH config values from the vagrant ssh-config command.
There are two thread one on stack overflow and another on superuser that might help you out with doing this. Links below.
How to connect with host PostgreSQL from vagrant virtualbox machine
https://superuser.com/questions/310697/connect-to-the-host-machine-from-a-virtualbox-guest-os/310745#310745
It is possible to do what you are trying to achieve if you get your settings correct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With