If you want to use a local MySQL manager or other application to connect to your database on stratus, an SSH tunnel is preferred where possible. 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/knowledge-base/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-virginia-24.mojostratus.io for the host and 20382 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 your stratus database host 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:
-L : :3306 @
SSHport and SSHhost can be found under SSH in your stratus panel. In this example the port is 20382 and the host is ssh-virginia-24.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 mojotest.
DBhost The database host is always mysql
Our example command ends up looking like this:
ssh -p 20382 -L 3306:mysql:3306 email@example.com
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.