Often, you will want to use database management tools such as MySQL Workbench or pgAdmin to work with your database instead of the command line. We do this by utilizing a command from the OC command line tools.
This document is assuming that you have already created and are using a database inside of Carolina CloudApps. The port forwarding aspects will function regardless of whether you have a database or not, and may be relevant depending on your needs. If you need help creating a database, please see: Carolina CloudApps: Creating and Using a Database. Additionally, it requires utilization of the OC command line tools. To install these, please follow this guide: Carolina CloudApps: Installing the Command Line Tools.
Open a terminal/command line window, and issue the following command:
oc get pods
Take note of the running database pod you want to connect to, e.g. mysql-2-3zw2g. Copy this to your clipboard, and then run the following command:
oc port-forward mysql-2-3zw2g 3306:3306
Where the command parameters look like this
oc port-forward PODNAME LOCALPORT:REMOTEPORT
and REMOTEPORT is the port that your database is listening on. To find the port number, log into console.cloudapps.unc.edu, select Applications -> Pods from the left-hand side, then select your database container. On the right-hand side, you should see the port number listed as part of the template.
Of note, the ports themselves do not need to match…for example, if you’ve already bound 3306 to a connection, you can run the following command:
oc port-forward PODNAME 9999:3306
This will bind 9999 on your localhost to 3306 on the pod.
Leveraging your forwarded port
In your database management tool of choice, you’re going to specify connections to localhost or 127.0.0.1, using the port number that you bound as the LOCALPORT. You will need to use the credentials that you specified upon creating the database. If you did not specify the credentials, they were automatically generated for you. To view them, do the following:
- Log into console.cloudapps.unc.edu
- On the left-hand side, select Applications -> Pods.
- Find the “Running” database container, and select it.
- Select the Environment tabs, and take note of the username and password.
Once you specify these, you should be able to then establish a connection to your database.
If you need further assistance, please feel free to send us an email at email@example.com.