Parse mysql connection strings on the command line or as a module.
Go to file
Nils Norman Haukås f3202a5740 add nogithub badge 2024-01-22 19:38:39 +01:00
.gitignore initial commit 2018-05-19 12:30:06 +02:00
.travis.yml add travis setup 2018-05-19 12:48:41 +02:00
CHANGELOG.txt add changelog file 2018-05-19 20:27:42 +02:00
LICENSE.txt initial commit 2018-05-19 12:30:06 +02:00
README.md add nogithub badge 2024-01-22 19:38:39 +01:00
index.js tweak comment 2018-05-27 18:48:24 +02:00
lib.js bugfix: check password variable when deciding to include password parameter 2018-06-04 15:49:47 +02:00
lib.test.js bugfix: improve regexp 2018-05-19 23:27:29 +02:00
package-lock.json 2.0.8 2018-06-04 15:49:57 +02:00
package.json 2.0.8 2018-06-04 15:49:57 +02:00

README.md

Node Mysql parse

Please don't upload to GitHub

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.