Languages
[Edit]
EN

HeidiSQL - connect to MySQL database via SSH Tunnel

8 points
Created by:
JustMike
3518

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:

HeidiSQL connection path to MySQL via SSH Tunnel
HeidiSQL connection path to MySQL via SSH Tunnel

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 to my-ssh-server.com.

Read below steps to see how to configure, save and open that database connection.

Simple steps:

  1. create new session configuration,
    in below case, session name is: my_db_user_name@my-ssh-server.com - but we use any name,
  2. 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
    where:
    • SSH tunnel option is verry important,
    • 127.0.0.1 and¬†3306¬†indicate¬†MySQL client connection configuration necessary to make connection from my-ssh-server.com¬†internal network.
  3. 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
    where:
    • C:\Program Files\PuTTY\plink.exe is part of PuTTY software,
    • 3307 is any port used only to make connection from your computer to¬†my-ssh-server.com, it can be changed to any unused port.
  4. save configuration,
  5. open connection.

Screenshots: 

MySQL client connection configuration - HeidiSQL
MySQL client connection configuration - HeidiSQL
MySQL client connection configuration via SSH tunnel - HeidiSQL
MySQL client connection configuration via SSH tunnel - HeidiSQL
Hey ūüĎč
Would you like to know what we do?
  • Dirask is a friendly IT community for learners, professionals and hobbyists to share their knowledge and help each other in extraordinary easy way.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.