To use a local MySQL manager or other application to connect to a database on STRATUS, an SSH tunnel is preferred. SSH tunnels are possible with a variety of clients. Putty and OpenSSH are used in the following examples.
Before you can connect, you need several pieces of information:
- A working SSH login to your STRATUS instance.
- The IP address that will connect to the STRATUS MySQL (i.e., the same IP allowed for SSH access)
- Your database credentials. In your STRATUS management 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 on your computer.
- Enter the SSH Host address shown SSH > Info.
- From the left-hand tree in PuTTY, go to Connection > SSH > Tunnels.
- Source Port — Enter "3306". If MySQL is locally using this port, enter another port number (e.g. "3307").
- Destination — Enter the STRATUS hostname combined with the host port of "3306" (e.g. "ssh.5uiwe1x3ngdgg75c.mojostratus.io:3306")
- Click Add.
- Click Open. Accept the SSH if requested.
- Log in with the STRATUS SSH User credentials.
The SSH tunnel to the remote database is now open. Connect locally using a MySQL client application. Use an IP of 127.0.0.1 and port number of 3306.
Creating a Tunnel with OpenSSH
A secure tunnel to the STRATUS database can be created using one command line:
ssh -p <SSHport> -L <localport>:mysql:3306 <SSHuser>@<SSHhost>
- SSHport — Use the SSH Port found in your SSH Info panel.
- localport — Normally "3306", the local port used to access MySQL. If an instance of MySQL is already running locally, an alternative port may be used, such as "3307".
- SSHuser — STRATUS SSH Username.
- SSHhost — Found in the STRATUS SSH Info panel.
Using this format, a typical OpenSSH tunnel might be created using:
ssh -p 21937 -L 3306:mysql:3306 email@example.com
After entering this into the terminal window, enter the STRATUS SSH user password.
While this tunnel connection is open, open a new terminal window and connect to the STRATUS MySQL database as if it were local.
SSH tunnels between STRATUS instances
SSH tunnels have become common between STRATUS instances for the purpose of Magento1->Magento2 data migrations. A tunnel between instances is very similar to creating a tunnel with OpenSSH, except for the following:
- Instead of SSH hostname, you must use the external IP address of the SSH host instead. For example, in the example above, for ssh.5uiwe1x3ngdgg75c.mojostratus.io, you would use the IP 184.108.40.206 instead.
You can obtain the outgoing/SSH IP of the instance you are on via ssh with the command curl http://ipcheck.com/
Below is a full example of the steps needed to create an SSH tunnel between 2 instances (M1 and M2)
Create a new SSH user on the M1 instance, allow the public SSH key & white-list the IP from the M2 instance. (curl http://ipcheck.com/)
Create a screen on the M2 instance: screen -S tunnel
Run the following in the screen to open the tunnel to the M1 instance:
ssh -p <PORT> -L 3307:mysql:3306 <USER>@<IP OF M1>
ssh -p 22000 -L 3307:mysql:3306 firstname.lastname@example.org
- Hit Ctrl-A-D on PC to disconnect from the screen without exiting the tunnel
You can now access both databases on the M2 instance:
Local m2 database: mysql -u user_abcdefghijk -p db_abcdefghijk Remote m1 database: mysql -u user_zyxwvutsrq -p -P 3307 db_zyxwvutsrq
If the M2 instance is rebooted, you will need to recreate the tunnel starting at step 2 above.