UNPKG

mysql-parse

Version:

Parse a mysql connection string and return access parameters that can be fed to the mysql or mysqldump command line client.

73 lines (45 loc) 2.18 kB
# Node Mysql parse [![Please don't upload to GitHub](https://nogithub.codeberg.page/badge.svg)](https://nogithub.codeberg.page) [![Hippocratic License HL3-FULL](https://img.shields.io/static/v1?label=Hippocratic%20License&message=HL3-FULL&labelColor=5e2751&color=bc8c3d)](https://firstdonoharm.dev/version/3/0/full.html) 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 ```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' */ ``` ## 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 Hippocratic License v3, [see license](LICENSE.md).