Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't connect to Vagrant using HeidiSQL: "Can't connect to MySQL server on 'localhost'"

I'm using Scotch Box, an awesome Vagrant LAMP stack.

I was able to setup everything on my Macbook in < 5 minutes, but I'm having issues getting it working on my Windows machine.

When I try to connect to the vagrant database using the HeidiSQL client, I receive the following error:

image

Below are my connection settings:

image

image

I've also tried port 22 on the SSH Tunnel tab, and I've double checked my passwords:

MySQL: root/root

Vagrant: vagrant/vagrant

I've confirmed that the MySQL service is running, and I'm able to connect to MySQL via the command line when I ssh into the Vagrant instance.

Any idea why this isn't working out-of-the-box for me?

Thanks!

Edit:

Here's the Vagrantfile if it helps:

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

Vagrant.configure("2") do |config|

  config.vm.box = "scotch/box"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.hostname = "scotchbox"
  config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]

end
like image 769
Andrew Avatar asked Apr 27 '15 01:04

Andrew


1 Answers

One thing I overlooked is that "local port" under the SSH Tunnel tab is also required. To wrap it all together, there's three key ports to set.

If your Vagrantfile looks kind of like this:

Vagrant.configure("2") do |config|
    config.vm.network "forwarded_port", guest: 3306, host: 3310
    config.vm.network "private_network", ip: "192.168.100.11"
end

and Vagrant auto-forwards the SSH port (22) to, say 2222 (you can check this by vagrant ssh-config, then the HeidiSQL config should be as follows:

Red brackets highlight fields to change

As new Vagrant versions use a custom-generated SSH key, you will need that instead of the vagrant/vagrant user/pw combination. The keys can be found in project location\.vagrant\machines\default\virtualbox.

This is as of HeidiSQL 9.4.0.5130 (64 Bit) on Windows 10.

like image 149
Max Avatar answered Oct 06 '22 07:10

Max