Skip to content

Instantly share code, notes, and snippets.

@rmatil
Created March 25, 2015 13:39
Show Gist options
  • Star 25 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save rmatil/8d21620c11039a442964 to your computer and use it in GitHub Desktop.
Save rmatil/8d21620c11039a442964 to your computer and use it in GitHub Desktop.
Connect MySQL database in Vagrant VM from Host machine

Connecting to Vagrant VM MySQL database from host

This gist shows how to connect to your vagrant MySQL database from the host machine.

Change Address Binding from MySQL

  • Connect to vagrant using vagrant ssh
  • Edit file /etc/mysql/my.cnf:
    • Change parameter bind-address to 0.0.0.0 to allow all incoming connection attempts
    • NOTE: Do not allow this in production
  • Change privileges of the MySQL user to allow connection attempts from any host:
    • On host connect as root user using mysql -uroot -proot
    • mysql> appears
    • Insert GRANT ALL PRIVILEGES ON *.* TO username@'%' IDENTIFIED BY "password";
    • username@'%' grants access from all hosts

Connect to DB by using MySQL Workbench

  • Add a new connection with the following parameters
    • Connection Method: Standard TCP/IP over SSH
    • SSH Hostname: 127.0.0.1:2222 if your VM is listening on port 2222 (showing on VM startup)
    • SSH username: vagrant or your vagrant user
      • SSH Key File: Use the path showing at IdentityFile when you type vagrant ssh-config on your vagrant root folder (in case vagrant uses SSH auth method: private key. Showing on VM startup)
      • SSH Password: In case you use SSH auth method: password on your VM
    • MySQL Hostname: 127.0.0.1
    • MySQL Server Port: 3306
    • Username: Your MySQL username
@AaronPresley
Copy link

🎉 worked perfectly, thanks!

@RussiSunni
Copy link

thanks very much. Worked for me.

@mukotso
Copy link

mukotso commented Jan 5, 2022

THANKS

It worked......

@slucaslima
Copy link

perfect

worked for me, thanks

@marcelovani
Copy link

Nice work

@courageWae
Copy link

It worked like magic. Thanks

@marchetb
Copy link

Works on Sequel Ace too, Thank you :)

@microwavestine
Copy link

microwavestine commented Dec 27, 2023

I had to add

[mysqld]
bind-address = 0.0.0.0

to /etc/mysql/my.cnf

Works well, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment