Port Forwarding to Connect to MySQL Database of VirtualBox

31,023

Solution 1

Things to check:

  1. 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)

  2. Is your MySQL server set up to allow remote connections? Open /etc/mysql/my.cnf and verify that your bind-address is set to the private IP of the guest machine. Also, make sure your port 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

Share:
31,023

Related videos on Youtube

Bakhtiyor
Author by

Bakhtiyor

Updated on September 17, 2022

Comments

  • Bakhtiyor
    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
      Admin over 13 years
      Could you add the MySQL connection settings you're using? So we can help you further.
    • Admin
      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
    Bakhtiyor over 13 years
    You 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
    ayan4m1 over 13 years
    Glad that it ended up getting resolved. Enjoy!