Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

SSH – Connect to MySQL through SSH Tunnel

Thursday, April 16th, 2020 by Helge

ssh-icon-16Here is the second part of our SSH series. Now, we like to describe how to create a tunnel via SSH to remotely connect to your database. This is one of many practical use of the SSH method.

By default, the MySQL server listens only on localhost, which means it can be accessed only by applications running on the same host. Due to security considerations we do not allow connections to our normal MySQL server from outside our network. The negative impact it will bring to our customers is that (but on) can not connect to their databases via external software (eg MySQL Workbench) which is troublesome for many who prefer to work on these instead of via our web-based tools (such as phpMyAdmin). The solution to this is to use their SSH account with us to create a tunnel to send their traffic through and thus be able to make the connection from an external location.

In the following  post, you find a step by step guideline hot to create you own SSH Tunnel to remotely access your MySQL database

Before, you can start you need to make sure your tools are ready:

a) SSH account: this guide assumes that you have already set up an SSH account. If you have not done it yet, check THIS LINK for a guide that describes how to do this.

b) SSH client: If you shouldn’t have a SSH client yet, then please get one. There are plenty of free tools you can find in the internet. One of them is Putty. You can download that tool from e.g. THIS PAGE.Now, when your SSH account and your SSH client is ready, perform the following steps to create a  SSH tunnel:

1. Start Putty and add an account. In the “Host Name” should read ssh.servage.net and in “Saved Sessions” choose a name for the connection. You can choose the “real name” when you set up the SSH account to avoid confusion.

 

 

2. In the left menu, navigate now to Connection> SSH> Tunnels

3. Start by typing 3306 in the “Source port”. In the “Destination”, enter the host name of the database server followed by :3306

See picture below:

 

 

4. Then click “Add” button (highlighted in the image above).

5. Go back to the Sessions (the same view as the first image in this guide) in the left menu and click “Save”.

6. Start up your tunnel by clicking on “Open”.

7. Enter your SSH login and password:

 

 

Your SSH tunnel is active! Make sure not to shut down Putty while you should use the tunnel. You can now start working with your database, enter 127.0.0.1 as the host name, and your database data.

You can login using your SQL-client like for example MySQL Workbench. In this example, we use MySQL Workbench, then it looks like this:

 

 

Please consider

If you already have a local MySQL server on the same machine that you want to start your SSH tunnel from this will not work as they respond to the same port (3306).

SSH - Connect to MySQL through SSH Tunnel, 4.9 out of 5 based on 8 ratings
Categories: Guides & Tutorials
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

No comments yet (leave a comment)

You are welcome to initiate a conversation about this blog entry.

Leave a comment

You must be logged in to post a comment.