Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hjzheng/ssh2mysql
https://github.com/hjzheng/ssh2mysql
Last synced: 27 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/hjzheng/ssh2mysql
- Owner: hjzheng
- License: mit
- Created: 2019-09-12T05:04:47.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-07-12T02:56:02.000Z (over 1 year ago)
- Last Synced: 2024-09-21T10:08:30.066Z (about 2 months ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ssh2mysql
```js
npm install @jxz/ssh2mysql
``````ts
// config.json
// you can get db configuration description from mysql2 and
// ssh configuration description from tunnel-ssh"db": {
"type": "mysql",
"host": "10.0.1.57",
"port": 3306,
"username": "xxxx",
"password": "passwd",
"database": "db"
},
"ssh": {
"username": "root",
"host": "10.0.1.60",
"port": 22,
"dstHost": "10.0.1.57",
"dstPort": 3306,
"localHost": "127.0.0.1",
"localPort": 12345,
"privateKey": "/Users/hjzheng/.ssh/id_rsa"
}// execSql.ts
import * as ssh2mysql from '@jxz/ssh2mysql'
import { config } from '@ys/api'const fs = require('fs')
const dbConf = config.db
const sshConf = config.sshlet mysql
const execSql = async (sql: string) => {
if (!mysql) {
mysql = await ssh2mysql.connect(
{
...sshConf,
privateKey: fs.readFileSync(sshConf.privateKey),
},
{ ...dbConf, user: dbConf.username },
)
}
return mysql.execSql(sql)
}export default execSql
```