{"id":43360,"library":"mysql-ssh2","title":"MySQL-SSH2","description":"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.","status":"maintenance","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/SusonJohn/mysql-ssh","tags":["javascript","mysql","remote","tunnel","ssh2"],"install":[{"cmd":"npm install mysql-ssh2","lang":"bash","label":"npm"},{"cmd":"yarn add mysql-ssh2","lang":"bash","label":"yarn"},{"cmd":"pnpm add mysql-ssh2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"MySQL client driver for querying the database","package":"mysql2","optional":false},{"reason":"SSH tunnel client for establishing the connection","package":"ssh2","optional":false}],"imports":[{"note":"Package is CommonJS only; ESM import not supported.","wrong":"import mysqlssh from 'mysql-ssh'","symbol":"default","correct":"const mysqlssh = require('mysql-ssh')"},{"note":"CommonJS destructure; ESM not available.","wrong":"import { connect } from 'mysql-ssh'","symbol":"connect","correct":"const { connect } = require('mysql-ssh')"},{"note":"CommonJS destructure; ESM not available.","wrong":"import { close } from 'mysql-ssh'","symbol":"close","correct":"const { close } = require('mysql-ssh')"}],"quickstart":{"code":"const mysqlssh = require('mysql-ssh');\nconst fs = require('fs');\n\nmysqlssh.connect(\n    {\n        host: 'my-ssh-server.org',\n        user: 'me-ssh',\n        privateKey: fs.readFileSync(process.env.HOME + '/.ssh/id_rsa')\n    },\n    {\n        host: 'my-db-host.com',\n        user: 'me-db',\n        password: 'secret',\n        database: 'my-db-name'\n    }\n)\n.then(client => {\n    client.query('SELECT * FROM `users`', function (err, results, fields) {\n        if (err) throw err\n        console.log(results);\n        mysqlssh.close()\n    })\n})\n.catch(err => {\n    console.log(err)\n})","lang":"javascript","description":"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."},"warnings":[{"fix":"Always call mysqlssh.close() in a finally block or after query completion.","message":"Forgetting to call mysqlssh.close() after queries will leave the SSH tunnel open, potentially exhausting resources.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use CommonJS require() instead.","message":"The package does not support ESM imports; using 'import' will fail.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set dbConfig.host to the remote database hostname or IP.","message":"The dbConfig.host must be the actual database host reachable from the SSH server, not localhost.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consider alternatives like ssh-tunnel or direct SSH port forwarding with mysql2.","message":"The project appears to be in maintenance mode with no recent updates; use with caution for production.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'access':45,67 'allow':28 'appear':88 'avoid':43 'cadenc':83 'close':78 'config':37 'connect':11,36 'databas':32,63 'denial':46 'depend':52 'establish':12 'extend':17 'forc':40 'gateway':71 'host':33 'issu':47 'javascript':94 'localhost':41 'mainten':92 'manual':77 'minim':51 'mode':93 'mysql':2,5,10,21,44,95 'mysql-ssh':20 'mysql-ssh2':1,4 'mysql2':55 'origin':19 'packag':23,49,87 'predecessor':26 'promis':74 'provid':8 'rather':38 'reach':62 'releas':82 'remot':31,96 'requir':76 'specifi':29 'ssh':15,22,70 'ssh2':3,6,57,98 'suitabl':60 'thus':42 'tunnel':16,81,97 'unknown':85 'unlik':24 'use':73 'v1.0.1':7 'via':68","created_at":"2026-06-05T16:59:25.876850+00:00","updated_at":"2026-06-05T16:59:25.876850+00:00","problems":[{"fix":"Run 'npm install mysql-ssh2' (note the package name is mysql-ssh2, not mysql-ssh) and use require('mysql-ssh2').","cause":"Package not installed or imported incorrectly with ESM.","error":"Error: Cannot find module 'mysql-ssh'"},{"fix":"Set dbConfig.host to the actual remote database hostname.","cause":"Using localhost as dbConfig.host when the database is not on the SSH server itself.","error":"Error: connect ECONNREFUSED 127.0.0.1:3306"},{"fix":"Ensure the private key file path is correct and the passphrase (if any) is provided in sshConfig.passphrase.","cause":"SSH authentication fails due to incorrect private key or passphrase.","error":"Error: All configured authentication methods failed"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/SusonJohn/mysql-ssh2#readme","github":"https://github.com/SusonJohn/mysql-ssh","docs":null,"changelog":null,"pypi":null,"npm":"mysql-ssh2","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}