Skip to content

MySQL SSH Tunnel

If you want to use a local MySQL manager or other application to connect to your database on stratus, an SSH tunnel will be required.  SSH tunnels are possible with a variety of clients. In the examples below, we will be using Putty and OpenSSH.

Before you can connect, you need several pieces of information:

If you have the above, you can proceed.

Creating a tunnel with Putty

  1. Open PuTTy; you should see a screen like this: putty-92
  2. Enter the server address shown in stratus under SSH->Info. In this example, you would use ssh.2matujnv3pm9oamq.mojostratus.io for the host and 20674 for the port. ssh info-2
  3. From the left-hand tree, go to Connection->SSH->Tunnels 
  4. Set the “Source port” to 3306. This is the port you will use locally to connect to. If you have mysql installed on this port locally, you can choose another port (like 3307). Set the “Destination” to "mysql" and port 3306 and click Add. This information is located under the config tab of your stratus panel. putty tunnel-42
  5. Connect to the server by pressing the Open button.  Accept the SSH key if needed. Log in with your SSH credentials.
  6. Your tunnel is now open, connect locally using your MySQL client to 127.0.0.1 on port 3306. In the screenshot below MobaXterm was used to connect on the default port and we can see the database via the MySQL CLI mobaxterm-91

Creating a tunnel with OpenSSH

You can create a tunnel with OpenSSH using one line:

ssh -p SSHPORT -L LOCALPORT:mysql:3306 SSHUSER@SSHHOST

openssh-49

SSHPORT and SSHHOST can be found under SSH in your stratus panel. In this example the port is 20674 and the host is ssh.2matujnv3pm9oamq.mojostratus.io

localport is the port you want to use mysql locally. This is normally port 3306, but if you are running mysql locally, you will want to change this port to something else (like 3307). For this example, we are using port 3306.

SSHUSER is the SSH user you created under the SSH section in your stratus panel. For this example, we are using jackie_mm.

DBhost The database host is always mysql

Our example command ends up looking like this:

ssh -p 20674 -L 3006:mysql:3306 jackie_mm@ssh.2matujnv3pm9oamq.mojostratus.io

While this tunnel connection is open, if you open a new terminal, you will see that you can now connect to your mysql database as if it were local.

open ssh stratus-71