If you want to connect to Vagrant MySQL server with MySQL Workbench in host machine, you will need to follow steps below.


Prerequisite



Vagrantfile


# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"

config.vm.define :symfony do |symfony_config|
symfony_config.vm.hostname = 'symfony'
symfony_config.vm.network "private_network", ip: "192.168.50.10"
end

config.vm.provider :virtualbox do |virtualbox_config|
virtualbox_config.name = "Symfony - Ubuntu 14.04"
end

config.vm.synced_folder "", "/var/www/html", nfs: true, mount_options: ["actimeo=2"]
end

Run vagrant box


Pay attention to SSH info below.


$ vagrant up
Bringing machine 'symfony' up with 'virtualbox' provider...
.....
.....
==> symfony: Forwarding ports...
symfony: 22 (guest) => 2222 (host) (adapter 1)
==> symfony: Booting VM...
==> symfony: Waiting for machine to boot. This may take a few minutes...
symfony: SSH address: 127.0.0.1:2222
symfony: SSH username: vagrant
symfony: SSH auth method: private key
==> symfony: Machine booted and ready!

You can obtain info above by running command below which is better option.


$ vagrant ssh-config

Host other
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/inanzzz/Webserver/symfony/.vagrant/machines/symfony/virtualbox/private_key
IdentitiesOnly yes
LogLevel FATAL

MySQL Workbench connection configuration


# Comes by default
SSH Hostname: 127.0.0.1:2222 # You can try with 22 as well

# Comes by default
SSH Username: vagrant

# This points to shared folder of host machine
SSH Key File: /Users/inanzzz/Webserver/symfony/.vagrant/machines/symfony/virtualbox/private_key

# Set this in "/etc/apache2/apache2.conf" file of vagrantbox as "ServerName localhost"
MySQL Hostname: localhost

# Comes by default
MySQL Server Port: 3306

# Whatever you set for MySQL
Username: root

# Whatever you set for MySQL
Password: 123123

Connection test




After the first attempt, error below will occur but don't get excited about it and try again.