How to connect to Mysql Server inside VirtualBox Vagrant?
Solution 1:
Make sure MySQL binds to 0.0.0.0 and not 127.0.0.1 or it will not be accessible from outside the machine
You can ensure this by editing the /etc/mysql/my.conf
file and looking for the bind-address
item--you want it to look like bind-address = 0.0.0.0
. Then save this and restart MySQL:
sudo service mysql restart
If you are doing this on a production server, you want to be aware of the security implications, discussed here: https://serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to-0-0-0-0
Solution 2:
Log in to your box with ssh [email protected] -p 2222
(password vagrant)
Then: sudo nano /etc/mysql/my.cnf
and comment out the following lines with #
#skip-external-locking
#bind-address
save it & exit
then: sudo service mysql restart
Then you can connect through SSH to your MySQL server.
Solution 3:
I came across this issue recently. I used PuPHPet to generate a config.
To connect to MySQL through SSH, the "vagrant" password was not working for me, instead I had to authenticate through the SSH key file.
To connect with MySQL Workbench
Connection method
Standard TCP/IP over SSH
SSH
Hostname: 127.0.0.1:2222 (forwarded SSH port)
Username: vagrant
Password: (do not use)
SSH Key File: C:\vagrantpath\puphpet\files\dot\ssh\insecure_private_key
(Locate your insercure_private_key)
MySQL
Server Port: 3306
username: (root, or username)
password: (password)
Test the connection.
Solution 4:
For anyone trying to do this using mysql workbench or sequel pro these are the inputs:
Mysql Host: 192.168.56.101 (or ip that you choose for it)
username: root (or mysql username u created)
password: **** (your mysql password)
database: optional
port: optional (unless you chose another port, defaults to 3306)
ssh host: 192.168.56.101 (or ip that you choose for this vm, like above)
ssh user: vagrant (vagrants default username)
ssh password: vagrant (vagrants default password)
ssh port: optional (unless you chose another)
source: https://coderwall.com/p/yzwqvg
Solution 5:
Well, since neither of the given replies helped me, I had to look more, and found solution in this article.
And the answer in a nutshell is the following:
Connecting to MySQL using MySQL Workbench
Connection Method: Standard TCP/IP over SSH
SSH Hostname: <Local VM IP Address (set in PuPHPet)>
SSH Username: vagrant (the default username)
SSH Password: vagrant (the default password)
MySQL Hostname: 127.0.0.1
MySQL Server Port: 3306
Username: root
Password: <MySQL Root Password (set in PuPHPet)>
Using given approach I was able to connect to mysql database in vagrant from host Ubuntu machine using MySQL Workbench and also using Valentina Studio.