Remote Database Access

How to connect to your database from another server or computer

Karl avatar
Written by Karl
Updated this week

The only way to access your database remotely from another server or computer is by first setting up a SSH tunnel to your Templ site.

Set up SSH tunnel

Setting up the SSH tunnel between your Templ site and remote is can be done with the following command.

ssh -p PORT USER@IPADDRESS -L127.0.0.1:3306:/var/run/mysqld/mysqld.sock

Execute the above command from your remote server or computer. Be sure to replace PORT, USER and IP ADDRESS with the real credentials that you find on your Site details page in the Templ Panel.

Accessing Database

Once the SSH tunnel has been set up, then the database can be accessed with the following command.

mysql

Note: If you already have a database set up that is using port 3306 then you will need to create the SSH tunnel on a different port and use that port instead, like port 3307.

Did this answer your question?