Provides a wrapper around mysql2 to create a MySQL connection over an SSH tunnel using ssh2. Enables async/await patterns for establishing the tunnel and executing queries. Current version 1.2.0, forks grrr-amsterdam/mysql-ssh with modern async support. Key differentiator: simple Promise-based API versus older callback-based alternatives. Key differentiator: simple Promise-based API versus older callback-based alternatives. Requires both mysql2 and ssh2 as peer dependencies. Release cadence is low, mainly bug fixes.
npm install mysql2-sshNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates async/await usage for creating an SSH tunnel to a MySQL database, running a query, and closing the tunnel.
Always call await close() in a finally block after your queries.
Use dynamic import: const { getConnection } = await import('mysql2-ssh')Upgrade Node.js to >=12.
Convert key to OpenSSH format using ssh-keygen -p -m PEM -f keyfile
Use 'await import('mysql2-ssh')' or set 'type': 'module' in package.jsonVerify SSH credentials and key format; use ssh -i key user@host to test
Ensure MySQL is running and accessible on the remote host; check dbConfig.host and port
npm install mysql2