HeidiSQL - connect to MySQL database via SSH Tunnel
In this article we would like to show how to connect to MySQL database using SSH Tunnel with HeidiSQL. This approach is recommended when we want to have secured connection with MySQL server or we don't have direct access to MySQL server and we need to connect to internal network to get access to MySQL server.
There ate two ways how to do it:
- with PuTTY SSH tunnel option,
- with HeidiSQL built-in SSH tunnel option.
This article presents second one option - easier option.
To better understand the way of getting connection look at simple visualisation:

As first we want to get connection with my-ssh-server.com
using SSH. Created SSH connection creates special tunnel that let us to pretend like we are located directly on my-ssh-server.com
. In our simple case MySQL server is located on the same machine with firewall and direct acces to it is not permitted. But we can use local IP address of MySQL server to get connection, because SSH tunnel forwarded us to internal local my-ssh-server.com
network.
Note: port
3307
was used only to open SSH tunnel from My PC tomy-ssh-server.com
.
Read below steps to see how to configure, save and open that database connection.
- create new session configuration,
in below case, session name is:my_db_user_name@my-ssh-server.com
- but we use any name, - in Settings tab use following configuration:
where:
xxxxxxxxxx
1Network type: MariaDB or MySQL (SSH tunnel)
2Hostname / IP: 127.0.0.1
3User: my_db_user_name
4Password: my_db_user_password
5Port: 3306
SSH tunnel
option is verry important,127.0.0.1
and3306
indicate MySQL client connection configuration necessary to make connection frommy-ssh-server.com
internal network.
- in SSH tunnel tab use following configuration:
where:
xxxxxxxxxx
1plink.exe location: C:\Program Files\PuTTY\plink.exe
2SSH host + port: my-ssh-server.com 22
3Username: my_ssh_user_name
4Password: my_ssh_user_password
5Local port: 3307
C:\Program Files\PuTTY\plink.exe
is part of PuTTY software,3307
is any port used only to make connection from your computer tomy-ssh-server.com
, it can be changed to any unused port.
- save configuration,
- open connection.

