can't access fortrabbit mysql db through terminal (ssh)

1.5k views Asked by At

I can't access mysql through terminal on fortrabbit. I follow all steps but it is rejecting my password. However I can regullary login through ssh and edit my application. Anyone had that issue ? Thanks.

1

There are 1 answers

4
msturdy On BEST ANSWER

I have solved this in the past using a SSH tunnel. You open an SSH tunnel to the server, and then you connect to the MySQL server there from the endpoint of that tunnel. As such, to MySQL you appear to be connecting locally.

From the terminal:

First you need to open the tunnel, you can do it like this:

ssh -N -L8889:127.0.0.1:3306 [email protected] &

This opens port 8889, then opens a tunnel to your.fortrabbit.domain.com, then forwards that local port through the tunnel to the IP 127.0.0.1 and port 3306 relative to the server at your.fortrabbit.domain.com.

The options in more detail:

-N: Do not execute a remote command.
-L: Specifies the ports (local and remote).
8889: Your local port that is being forwarded.
127.0.0.1: the remote IP to which you're forwarding, relative to the server which ssh is connecting to
3306: the remote port to which you're forwarding.
[email protected]: Your username and domain with fortrabbit.

Now you're ready to open the connection. In the same terminal, use the following command:

mysql -h 127.0.0.1 -P 8889 -u mysql-username -p

port 8889 is now being forwarded to the port and IP of your MySQL server on the fortrabbit side, so just replace mysql-username with your username on the mysql server, and you're connected!

From a GUI:

You mentioned in your comments that you're using Ubuntu, so install MySQL Workbench from the Software Centre or here, create a New Connection and select the connection type as "Standard TCP/IP over SSH".

You will need to configure the following:

SSH Hostname: the hostname or IP of your ssh account with fortrabbit
SSH Username: your username with them
SSH Password: your password with them
SSH Keyfile: If you use keys for authentication, select the private one here.
MySQL Hostname: 127.0.0.1 (because it's local to the endpoint of your tunnel.
MySQL Server Port: normally "3306".
Username: The username for the DB
Password: The password for the DB
Default Schema: Whatever should be the default schema for this DB (can be left blank).

That should then connect from wherever you are!