Node Mysql parse
Tired of manually extracting login credentials from mysql connection strings? Look no further!
This package parses mysql connection strings both on the command line or as a module.
Installation
Two options:- Global installation
npm install -g mysql-parse
.
- Local installation
npm install mysql-parse
.
Usage on command line
BasicRunning
mysql-parse mysql://examplename:somepassword@examplehost:3306/dbname)
will generate string like this -u examplename -psomepassword -h examplehost -P 3306 dbname
which you can pass to mysql or mysqldump commands.Using mysql
mysql $(mysql-parse <some mysql connection string>)
Using mysqldump
mysqldump $(mysql-parse <some mysql connection string>) > dump.sql
Passing in other options to mysql/mysqldump
Because the last thing out of mysql-parse is the database name (if defined in the connection string), options need to be added before mysql-parse like so:
mysqldump --compact $(mysql-parse <some mysql connection string>) > dump.sql
Usage as module
const { buildMysqlParams, parseUri } = require('mysql-parse')
const testUri = 'mysql://examplename:somepassword@examplehost:3306/dbname'
console.log(parseUri(testUri))
/*
returns
{
user: 'examplename',
password: 'somepassword',
host: 'examplehost',
port: '3306',
database: 'dbname'
}
*/
console.log(buildMysqlParams(testUri))
/*
returns '-u examplename -psomepassword -h examplehost -P 3306 dbname'
*/
Development
- Download this project.
- Run tests with
npm test
. - Develop and submit PR. Please note: If you are considering substantial changes, please open an issue to discuss first because the feature you're thinking of might not be right for this project.