June 6, 2018 · Setup Guides

Connect MySQL Workbench with MySQL/MariaDB in Vagrant over SSH

This post outlines how to connect MySQL Workbench with a MySQL/MariaDB service running inside a Vagrant Virtualbox VM over SSH.

I. Configure Vagrant

To make sure that the port does not change and mess up your MySQL Workbench config, it is a good idea to set a fixed SSH port for your VM. For this example, I used 2222.

Include this line in your Vagrantfile:

config.ssh.guest_port = 2222

II. Configure MySQL Workbench

By default, vagrant creates a privatekey at:

.vagrant/machines/<hostname>/virtualbox/private_key

Open up MySQL Workbench and setup a new connection the following parameters:

  • Connection Method: Standard TCP/IP over SSH
  • SSH Hostname: 127.0.0.1:2222
  • SSH Username: vagrant
  • SSH Key File: .vagrant/machines/<hostname>/virtualbox/private_key

Make sure to fill in "Username" and "Password" with your database's details.

Here's an example:

Screenshot-from-2018-06-06-00-54-40-2

Click on "Test Connection" to try it out then click on "Ok" to save the connection.

Done!