Znote (recipes)
  Get Znote  

SQL query on remote database

How to make SQL query on a remote MySQL

 

Connect to a remote SQL database

👉 Install the Remote SQL plugin 🧩

1 - Make an SQL query with SSH Start to create an SSH key

ssh-keygen -t rsa -N '' -f my-ssh-key

Copy your ssh key on your server (open a terminal to run this command and enter your password)

ssh-copy-id -i my-ssh-key user@XXX.ovh.net

Usage

//exec:node
const query = "select * from TABLE;";

const dialect = "mysql"; //'mysql' | 'postgres' | 'mssql'
const port = 3306; // mysql,mariadb=3306 postgres=5432 mssql=1433
const results = await getRemoteSQL(query, "my-ssh-key", 3307, port, "user@XXX.ovh.net", dialect, "user", "password", "database");
printJSON(results);

Related recipes