Recently I got the following question from Mostafa Hashem:
First I need to thank you for sharing your experience with us.
I need to ask you about something related to Vagrant & MySQL service.
I need to connect to MySQL databases outside SSH for example fromSqlYog.
But to be honest with you I spent a lot of time on it and I don’t have a good experience on server side.
Could you help me in that , I will be appreciated.
Well Mostafa, the answer is actually pretty easy…
Connect to MySQL in Vagrant
When you instantiate a Vagrant box, Vagrant automatically forwards port 2222 to your guest machines’ 22. This is also how you can connect to your Vagrant Boxes SSH client when you type vagrant ssh in your terminal. The same port can be set with most MySQL GUI’s when entering the credentials. So when you’re connecting to MySQL, you have to:
- Enter 127.0.0.1 as the host
- Enter your MySQL username and password
- Enable the SSH-tunnel
- Enter the default vagrant username and password (this is vagrant and vagrant).
Example for Sequel Pro
Unfortunately, I can’t show an example for SqlYog (or any other Windows program) since I work on OSX. But in my experience, all MySQL Management programs have the option to enable SSH and set the port that is used for that. So you just have to look for that and it will work!
More advanced tunneling
If you’re looking for more advanced SSH tunneling in Vagrant, you might be interested in this article I wrote a while ago. It describes how to setup an SSH tunnel from the command line so you can access MySQL on a different port.
Visitors give this article an average rating of 3.6 out of 5.
How would you rate this article?
★ ★ ★ ★ ★