Run an SQL Query Through SSH
This post shows you how you can connect to a database remotely via an SSH connection. This is especially useful if the database isn’t accessible due to firewall rules - for example on a web server. But if you have SSH access, it’s just like logging in and running the command yourself.
This is possible with port forwarding through an SSH connection on our machine, like shown below, but it’s more consise and simpler being part of a single script.