Database access via terminal

Published

Updated

💻

Connect through command line interface.

Open an SSH tunnel to the fortrabbit environment in one terminal window, then connect the mysql client through it in a second one. The password is in the MySQL settings of the environment in the dashboard.

Run these commands on the local computer, with the mysql client installed. The commands may differ with the local development environment.

# 1. Create a tunnel in a dedicated terminal window
ssh -N -L 13306:mysql:3306 {{app-env-id}}@ssh.{{region}}.frbit.app
# This will have no output. That's Ok. Open a new window
shell
# 2. In a new window connect to the database
$ mysql -u {{app-env-id}} -h127.0.0.1 -P13306 -p -D {{app-env-id}}
# In the next step you will be asked for your MySQL password.
shell

Next

Port setting

The local port 13306 is an example, any free port from 1025 to 65535 works. The remote side stays mysql:3306.

Troubleshooting

  • The tunnel command prints nothing while it runs. That is right: leave it open and continue in a new window.
  • Connect to 127.0.0.1, not localhost: with localhost, the client looks for a local socket instead of the tunnel.

Written by humans and AI in collaboration.

AI use & editorial processEdit on GitHub ↗