Run a SQL Query Through SSH
This post shows how you can connect to a database remotely via a SSH connection. In our example we’ll be connecting to a MySQL or MariaDB database, but the same method will apply to many other SQL databases like PostgreSQL. This technique 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.