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:
- A working SSH login to your Stratus instance: https://magemojo.com/kb/stratus-management-panel/stratus-ssh/stratus-ssh-access/
- The IP you will be connecting to MySQL from (this should be the same IP you whitelisted for SSH access)
- Your database credentials. In your Stratus managment panel, expand the MySQL section and click Info to see your database username and password
If you have the above, you can proceed.
Creating a tunnel with Putty
- Open PuTTy; you should see a screen like this:
- 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.
- From the left-hand tree, go to Connection->SSH->Tunnels
- 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.
- Connect to the server by pressing the Open button. Accept the SSH key if needed. Log in with your SSH credentials.
- 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
Creating a tunnel with OpenSSH
You can create a tunnel with OpenSSH using one line:
ssh -p SSHPORT -L LOCALPORT:mysql:3306 SSHUSER@SSHHOST
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 firstname.lastname@example.org
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.