Can’t connect to Vagrant using HeidiSQL: “Can’t connect to MySQL server on ‘localhost’”

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: Below are my connection settings: 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| = "scotch/box" "private_network", ip: "" config.vm.hostname = "scotchbox" config.vm.synced_folder ".", "/var/www", :mount_options => [“dmode=777”, “fmode=666”]



Solution 1:

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| "forwarded_port", guest: 3306, host: 3310 "private_network", ip: ""

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 (64 Bit) on Windows 10.

Solution 2:

This seems to be an issue with the version of HeidiSQL I was using. Upgrading to HeidiSQL 9.1 allowed me connect.

Solution 3:

I still experience this issue in HeidiSQL 9.3. I’ve found that suspending and reloading the vagrant box can make it go away.

Solution 4:

Got similar issue but on Ubuntu(using wine). The problem was that we use IP for vagrant virtual machine that starts from “192.”.
Solve simply adding host on hosts file as “192.bla.bla.bla” and use domain “” instead IP in HeidiSQL “SSH tunnel” page.

Solution 5:

Though i got no luck connecting via MYSQL (TCP/IP) setting, i found a solution to the problem.

You need to connect via MYSQL (ssh tunnel), enter corresponding password, connect with plink (you will find link in HeidiSQL itself) and set plink timeout to number >10-20.

Tested it with 9.3 build 5901.

This solution was also mentioned in scotchbox issue on github.