For that, you'd have to establish an SSH tunnel using something like autossh.
Do you control the database server? If this is a live service, it's better to use direct DB connections secured with TLS. You can restrict access to specific IPs using firewall rules.
@mostafa-amine You don’t, because that’s just going to cause unnecessary latency in your application as it establishes an SSH connection, and then connects to the database. Your web app’s server should be whitelisted to be allowed to connect to the MySQL database server instead.