Port Forwarding to Connect to MySQL Database of VirtualBox
Solution 1
Things to check:
What is the "host" field set to for your MySQL user? If it is
localhost
or similar then the MySQL server is denying access because you are connecting from an external machine. Change the host field to%
to allow connections from any IP (though obviously never use this in a production environment where the guest is accepting connections from the Internet)Is your MySQL server set up to allow remote connections? Open
/etc/mysql/my.cnf
and verify that yourbind-address
is set to the private IP of the guest machine. Also, make sure yourport
setting matches whatever you are trying to connect on.
Beyond that, you'll need to post logs or connection information so that we can take a closer look at the actual problem.
Solution 2
Instead of using the port forwarding for each application you can use the 'Bridged networking' for your guest os. So that you can assign an ip with same subnet mask as your host system. For example if your host sytem's ip is 192.168.0.10 ,after enabling the bridged networking you can assign a similar ip to the guest also, say 192.168.1.11. Thus you can access all services running on guest as normal. Read the below link for more info about setting up bridged network. It is an easy task will not take more than 2 minute.
http://www.virtualbox.org/manual/ch06.html
Related videos on Youtube
Bakhtiyor
Updated on September 17, 2022Comments
-
Bakhtiyor over 1 year
I have Ubuntu 10.04 as host machine and Ubuntu 10.10 as guest machine installed in VirtualBox.
I had success on port forwarding to connect to Apache of guest machine, so that now I can open in host machine web sites published in Web Server(Apache) of guest machine.
I need to do the same with MySql, i.e. access MySql of guest machine from host machine.
In order to achieve this goal I am executing following commands in host machine:
VBoxManage setextradata Ubuntu "VBoxInternal/Devices/e1000/0/LUN#0/Config/mysql/HostPort" 3307 VBoxManage setextradata Ubuntu "VBoxInternal/Devices/e1000/0/LUN#0/Config/mysql/GuestPort" 3306 VBoxManage setextradata Ubuntu "VBoxInternal/Devices/e1000/0/LUN#0/Config/mysql/Protocol" TCP
where Ubuntu is the name of the host machine.
Guest machine loads and when I try to connect to MySql from host machine it can not connect to it.
What could be the problem here?
Thank you.
-
Admin over 13 yearsCould you add the MySQL connection settings you're using? So we can help you further.
-
Admin over 13 years"... where Ubuntu is the name of the host machine." Umm, no, you're editing the configuration of the guest machine. This means that your 10.04 mysql client needs to connect to localhost port 3307 to talk to the guest port 3306.
-
-
Bakhtiyor over 13 yearsYou are completely right. I havecommented bind-address and also configured mysql database so that to allow connections from any IP. Thank you for proposal.
-
ayan4m1 over 13 yearsGlad that it ended up getting resolved. Enjoy!