Registry / database / mysql-ssh2

mysql-ssh2

JSON →
library1.0.1jsnpmunverified

mysql-ssh2 v1.0.1 provides a MySQL connection established through an SSH tunnel, extending the original mysql-ssh package. Unlike its predecessor, it allows specifying a remote database host in the connection config rather than forcing localhost, thus avoiding MySQL access denial issues. The package is minimal, depending only on mysql2 and ssh2, and is suitable for reaching databases that are only accessible via an SSH gateway. It uses Promises and requires manual closing of the tunnel. Release cadence is unknown; the package appears to be in maintenance mode.

npm install mysql-ssh2
INSTALL
IMPORT
SIG · MYSQL-SSH2
M
mysql-ssh2
databasejavascriptv1.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const mysqlssh = require('mysql-ssh')
import mysqlssh from 'mysql-ssh'
Package is CommonJS only; ESM import not supported.
connect
const { connect } = require('mysql-ssh')
import { connect } from 'mysql-ssh'
CommonJS destructure; ESM not available.
close
const { close } = require('mysql-ssh')
import { close } from 'mysql-ssh'
CommonJS destructure; ESM not available.

Demonstrates establishing an SSH tunnel to a remote host and connecting to a MySQL database through that tunnel, running a query, and closing the connection.

const mysqlssh = require('mysql-ssh'); const fs = require('fs'); mysqlssh.connect( { host: 'my-ssh-server.org', user: 'me-ssh', privateKey: fs.readFileSync(process.env.HOME + '/.ssh/id_rsa') }, { host: 'my-db-host.com', user: 'me-db', password: 'secret', database: 'my-db-name' } ) .then(client => { client.query('SELECT * FROM `users`', function (err, results, fields) { if (err) throw err console.log(results); mysqlssh.close() }) }) .catch(err => { console.log(err) })
Debug
Known issues
gotchaForgetting to call mysqlssh.close() after queries will leave the SSH tunnel open, potentially exhausting resources.
fix
Always call mysqlssh.close() in a finally block or after query completion.
affects: >=1.0.0
gotchaThe package does not support ESM imports; using 'import' will fail.
fix
Use CommonJS require() instead.
affects: >=1.0.0
gotchaThe dbConfig.host must be the actual database host reachable from the SSH server, not localhost.
fix
Set dbConfig.host to the remote database hostname or IP.
affects: >=1.0.0
deprecatedThe project appears to be in maintenance mode with no recent updates; use with caution for production.
fix
Consider alternatives like ssh-tunnel or direct SSH port forwarding with mysql2.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mysql-ssh'
Package not installed or imported incorrectly with ESM.
fix
Run 'npm install mysql-ssh2' (note the package name is mysql-ssh2, not mysql-ssh) and use require('mysql-ssh2').
Error: connect ECONNREFUSED 127.0.0.1:3306
Using localhost as dbConfig.host when the database is not on the SSH server itself.
fix
Set dbConfig.host to the actual remote database hostname.
Error: All configured authentication methods failed
SSH authentication fails due to incorrect private key or passphrase.
fix
Ensure the private key file path is correct and the passphrase (if any) is provided in sshConfig.passphrase.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
mysql2requiredMySQL client driver for querying the database
ssh2requiredSSH tunnel client for establishing the connection
Agent activity
8 hits · last 30 days
node
8
Resources
mysql-ssh2 — npm install mysql-ssh2 · libregistry