Kill backgrounded SSH when shell exits

I’m trying to spawn an SSH from my bash profile script that runs in the background for connection sharing (via its control socket). The problem I’m running into is a reliable way to ensure the SSH doesn’t stay running once the TTY is closed (or more directly; once the parent bash shell has exited).

Copy text from one terminal into another

I am logged into ssh to a university account from my home computer. Then I find a file that I want to copy onto my local system. So I open a new shell terminal and am about to use scp to copy that file onto my system. But the path to the file on the system I am ssh‘ed into is long so I select it with the mouse and then paste it with the mouse into the other locally connected terminal.

AWS Lightsail WordPress – connect to database on instance using mysqli

I have a wordpress website hosted on AWS Lightsail. On that website, I would like to use a shortcode to retrieve data from a database using mysqli. However, everytime the script that connects to the database is executed, I receive a connection error. The database is on the same AWS Lightsail instance.
I was wondering if I need to establish an SSH-tunnel because this is also needed if I connect to phpmyadmin. But since the script is executed on the server itself this does not really makes sense in my understanding. I have used the exact same code on a local host and it worked perfectly fine. What am I missing here?