Parse a mysql connection string and return access parameters that can be fed to the mysql or mysqldump command line client.
npm install 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.
Two options:
* Global installation npm install -g mysql-parse.
* Local installation npm install mysql-parse.
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
Using mysqldump
mysqldump $(mysql-parse
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
``javascript
import { buildMysqlParams, parseUri } from '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'
*/
`
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.
Project code is licensed under the Hippocratic License v3, see license.