mysql-parse

2.0.8 • Public • Published

Node Mysql parse

Build Status

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

Basic

Running 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

  1. Download this project.
  2. Run tests with npm test.
  3. 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.

License

Project code is licensed under the MIT license, see license.

Package Sidebar

Install

npm i mysql-parse

Weekly Downloads

67

Version

2.0.8

License

MIT

Unpacked Size

6.6 kB

Total Files

8

Last publish

Collaborators

  • nilsnh