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
3307was used only to open SSH tunnel from My PC to
Read below steps to see how to configure, save and open that database connection.
- create new session configuration,
in below case, session name is:
email@example.com- but we use any name,
- in Settings tab use following configuration:
Network type: MariaDB or MySQL (SSH tunnel) Hostname / IP: 127.0.0.1 User: my_db_user_name Password: my_db_user_password Port: 3306
SSH tunneloption is verry important,
3306indicate MySQL client connection configuration necessary to make connection from
- in SSH tunnel tab use following configuration:
plink.exe location: C:\Program Files\PuTTY\plink.exe SSH host + port: my-ssh-server.com 22 Username: my_ssh_user_name Password: my_ssh_user_password Local port: 3307
C:\Program Files\PuTTY\plink.exeis part of PuTTY software,
3307is any port used only to make connection from your computer to
my-ssh-server.com, it can be changed to any unused port.
- save configuration,
- open connection.