Database sessions and SSH tunnels
A HeidiSQL session can contain a database endpoint and a separate SSH connection. Their ports, usernames and credentials have different roles. A profile read describes the relationship without opening either connection.
Inspect the relationship
Install @jalsoedesign/heidisql-core, follow language setup, and save the synthetic portable settings beside the selected program variant.
// inspect-tunnel.ts
import {HeidiSqlProfileSource} from '@jalsoedesign/heidisql-core';
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profile = source.get('Demo');
const database = profile?.connections.find(connection => connection.kind === 'database');
const ssh = profile?.connections.find(connection => connection.id === 'ssh');
if (!database || !ssh) {
throw new Error('The fixture must contain a database connection and SSH tunnel');
}
console.log('Database: ' + database.protocol + ' ' + database.endpoint.host + ':' + database.endpoint.port);
console.log('SSH: ' + ssh.endpoint.host + ':' + ssh.endpoint.port);
console.log('Database via: ' + database.via?.join(', '));
console.log('SSH authentication: ' + ssh.authentication.map(method => method.type).join(', '));
console.log('No SQL query or SSH tunnel was opened.');// inspect-tunnel.js
import {HeidiSqlProfileSource} from '@jalsoedesign/heidisql-core';
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profile = source.get('Demo');
const database = profile?.connections.find(connection => connection.kind === 'database');
const ssh = profile?.connections.find(connection => connection.id === 'ssh');
if (!database || !ssh) {
throw new Error('The fixture must contain a database connection and SSH tunnel');
}
console.log('Database: ' + database.protocol + ' ' + database.endpoint.host + ':' + database.endpoint.port);
console.log('SSH: ' + ssh.endpoint.host + ':' + ssh.endpoint.port);
console.log('Database via: ' + database.via?.join(', '));
console.log('SSH authentication: ' + ssh.authentication.map(method => method.type).join(', '));
console.log('No SQL query or SSH tunnel was opened.');// inspect-tunnel.mjs
import {HeidiSqlProfileSource} from '@jalsoedesign/heidisql-core';
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profile = source.get('Demo');
const database = profile?.connections.find(connection => connection.kind === 'database');
const ssh = profile?.connections.find(connection => connection.id === 'ssh');
if (!database || !ssh) {
throw new Error('The fixture must contain a database connection and SSH tunnel');
}
console.log('Database: ' + database.protocol + ' ' + database.endpoint.host + ':' + database.endpoint.port);
console.log('SSH: ' + ssh.endpoint.host + ':' + ssh.endpoint.port);
console.log('Database via: ' + database.via?.join(', '));
console.log('SSH authentication: ' + ssh.authentication.map(method => method.type).join(', '));
console.log('No SQL query or SSH tunnel was opened.');// inspect-tunnel.cjs
async function main() {
const {HeidiSqlProfileSource} = await import('@jalsoedesign/heidisql-core');
const source = await HeidiSqlProfileSource.fromFile(process.argv[2] ?? './portable_settings.txt');
const profile = source.get('Demo');
const database = profile?.connections.find(connection => connection.kind === 'database');
const ssh = profile?.connections.find(connection => connection.id === 'ssh');
if (!database || !ssh) {
throw new Error('The fixture must contain a database connection and SSH tunnel');
}
console.log('Database: ' + database.protocol + ' ' + database.endpoint.host + ':' + database.endpoint.port);
console.log('SSH: ' + ssh.endpoint.host + ':' + ssh.endpoint.port);
console.log('Database via: ' + database.via?.join(', '));
console.log('SSH authentication: ' + ssh.authentication.map(method => method.type).join(', '));
console.log('No SQL query or SSH tunnel was opened.');
}
main().catch(error => {
console.error(error);
process.exitCode = 1;
});Run it
npx tsx inspect-tunnel.tsnode inspect-tunnel.jsnode inspect-tunnel.mjsnode inspect-tunnel.cjsOutput
Database: mysql 127.0.0.1:3306
SSH: 127.0.0.1:22
Database via: ssh
SSH authentication: private-key, password
No SQL query or SSH tunnel was opened.Download: TypeScript · JavaScript · MJS · CommonJS
The database's via list points to the SSH connection ID in the same profile. Select ssh when syncing only the tunnel endpoint to an SSH application. Password references for the database and tunnel are independent; a private-key path is a file on the host.
What happens after a read
Use a database client to run SQL or import/export data. Use a suitable SSH implementation for tunnelling and host verification. This library supplies saved metadata; it does not run queries, dump databases or create a live tunnel.
See supported projections, connecting a selected profile and writing/sync.