Read and Display MySQL objects and their relationship in a force-directed graph.
MySQL have a sample database called sakila and the demo below is the the result of analyzing the information_schema
There are already tools that can read Entity-Relationship Diagrams and display the cardinality and foreign keys of each objects. The problem with ERD is once the number of tables got higher than 20 or so, displaying such diagram can be hard to read.
graphmysql
addresses this problem by only displaying the table names as circles, then the relationship as lines. This gives you a gist of which tables is connected to which in lets say a 100+ tables database. The interactivity it also provides natural way of "weeding" out unrelated tables by dragging away the node from the majority through force-directed graphs.
This tool is useful for the following use-cases:
- Getting an overview of how each tables is all related in the big picture
- Change management - if you drop a certain table, which ones will be affected
- Partial Updating/Resetting of database - if the production data is very huge, grabbing an entire db dump might not be ideal, determining only related tables is more practical.
- Share with backend developer the relationship of each tables (table names, foreign keys) in order to create Models in (MVC).
- Non-technical tool to communicate business objects with stakeholders.
- MySQL Server 5.7 or higher
- NodeJS 18 or higher
$ npm install -g graphmysql
$ graphmysql COMMAND
running command...
$ graphmysql (--version)
graphmysql/1.0.3 darwin-x64 node-v20.11.0
$ graphmysql --help [COMMAND]
USAGE
$ graphmysql COMMAND
...
graphmysql build GRAPH
graphmysql explore DATABASE HOST PASSWORD USERNAME
graphmysql help [COMMANDS]
graphmysql plugins
graphmysql plugins:install PLUGIN...
graphmysql plugins:inspect PLUGIN...
graphmysql plugins:install PLUGIN...
graphmysql plugins:link PLUGIN
graphmysql plugins:uninstall PLUGIN...
graphmysql plugins reset
graphmysql plugins:uninstall PLUGIN...
graphmysql plugins:uninstall PLUGIN...
graphmysql plugins update
graphmysql serve GRAPH PORT
generate a static html file that allows you to browse graph data
USAGE
$ graphmysql build GRAPH
ARGUMENTS
GRAPH Path to a JSON file that constains the graph data
DESCRIPTION
generate a static html file that allows you to browse graph data
EXAMPLES
$ graphmysql build ./graph.json
See code: src/commands/build.ts
Connect to MySQL database and generate a json graph data.
USAGE
$ graphmysql explore DATABASE HOST PASSWORD USERNAME
ARGUMENTS
DATABASE MySQL database
HOST MySQL Host
PASSWORD MySQL password
USERNAME MySQL username
DESCRIPTION
Connect to MySQL database and generate a json graph data.
EXAMPLES
$ graphmysql explore your_db 127.0.0.1 yourpassword youruser > graph.json
See code: src/commands/explore/index.ts
Display help for graphmysql.
USAGE
$ graphmysql help [COMMANDS] [-n]
ARGUMENTS
COMMANDS Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
Display help for graphmysql.
See code: @oclif/plugin-help
List installed plugins.
USAGE
$ graphmysql plugins [--json] [--core]
FLAGS
--core Show core plugins.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
List installed plugins.
EXAMPLES
$ graphmysql plugins
See code: @oclif/plugin-plugins
Installs a plugin into the CLI.
USAGE
$ graphmysql plugins add plugins:install PLUGIN...
ARGUMENTS
PLUGIN Plugin to install.
FLAGS
-f, --force Run yarn install with force flag.
-h, --help Show CLI help.
-s, --silent Silences yarn output.
-v, --verbose Show verbose yarn output.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Installs a plugin into the CLI.
Can be installed from npm or a git url.
Installation of a user-installed plugin will override a core plugin.
e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
the CLI without the need to patch and update the whole CLI.
ALIASES
$ graphmysql plugins add
EXAMPLES
$ graphmysql plugins add myplugin
$ graphmysql plugins add https://github.com/someuser/someplugin
$ graphmysql plugins add someuser/someplugin
Displays installation properties of a plugin.
USAGE
$ graphmysql plugins inspect PLUGIN...
ARGUMENTS
PLUGIN [default: .] Plugin to inspect.
FLAGS
-h, --help Show CLI help.
-v, --verbose
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Displays installation properties of a plugin.
EXAMPLES
$ graphmysql plugins inspect myplugin
See code: @oclif/plugin-plugins
Installs a plugin into the CLI.
USAGE
$ graphmysql plugins install PLUGIN...
ARGUMENTS
PLUGIN Plugin to install.
FLAGS
-f, --force Run yarn install with force flag.
-h, --help Show CLI help.
-s, --silent Silences yarn output.
-v, --verbose Show verbose yarn output.
GLOBAL FLAGS
--json Format output as json.
DESCRIPTION
Installs a plugin into the CLI.
Can be installed from npm or a git url.
Installation of a user-installed plugin will override a core plugin.
e.g. If you have a core plugin that has a 'hello' command, installing a user-installed plugin with a 'hello' command
will override the core plugin implementation. This is useful if a user needs to update core plugin functionality in
the CLI without the need to patch and update the whole CLI.
ALIASES
$ graphmysql plugins add
EXAMPLES
$ graphmysql plugins install myplugin
$ graphmysql plugins install https://github.com/someuser/someplugin
$ graphmysql plugins install someuser/someplugin
See code: @oclif/plugin-plugins
Links a plugin into the CLI for development.
USAGE
$ graphmysql plugins link PLUGIN
ARGUMENTS
PATH [default: .] path to plugin
FLAGS
-h, --help Show CLI help.
-v, --verbose
--[no-]install Install dependencies after linking the plugin.
DESCRIPTION
Links a plugin into the CLI for development.
Installation of a linked plugin will override a user-installed or core plugin.
e.g. If you have a user-installed or core plugin that has a 'hello' command, installing a linked plugin with a 'hello'
command will override the user-installed or core plugin implementation. This is useful for development work.
EXAMPLES
$ graphmysql plugins link myplugin
See code: @oclif/plugin-plugins
Removes a plugin from the CLI.
USAGE
$ graphmysql plugins remove plugins:uninstall PLUGIN...
ARGUMENTS
PLUGIN plugin to uninstall
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Removes a plugin from the CLI.
ALIASES
$ graphmysql plugins unlink
$ graphmysql plugins remove
EXAMPLES
$ graphmysql plugins remove myplugin
Remove all user-installed and linked plugins.
USAGE
$ graphmysql plugins reset [--hard] [--reinstall]
FLAGS
--hard Delete node_modules and package manager related files in addition to uninstalling plugins.
--reinstall Reinstall all plugins after uninstalling.
See code: @oclif/plugin-plugins
Removes a plugin from the CLI.
USAGE
$ graphmysql plugins uninstall PLUGIN...
ARGUMENTS
PLUGIN plugin to uninstall
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Removes a plugin from the CLI.
ALIASES
$ graphmysql plugins unlink
$ graphmysql plugins remove
EXAMPLES
$ graphmysql plugins uninstall myplugin
See code: @oclif/plugin-plugins
Removes a plugin from the CLI.
USAGE
$ graphmysql plugins unlink plugins:uninstall PLUGIN...
ARGUMENTS
PLUGIN plugin to uninstall
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Removes a plugin from the CLI.
ALIASES
$ graphmysql plugins unlink
$ graphmysql plugins remove
EXAMPLES
$ graphmysql plugins unlink myplugin
Update installed plugins.
USAGE
$ graphmysql plugins update [-h] [-v]
FLAGS
-h, --help Show CLI help.
-v, --verbose
DESCRIPTION
Update installed plugins.
See code: @oclif/plugin-plugins
Render Graph data to a simple HTTP Server.
USAGE
$ graphmysql serve GRAPH PORT
ARGUMENTS
GRAPH Path to a JSON file that constains the graph data
PORT which port to serve the http server
DESCRIPTION
Render Graph data to a simple HTTP Server.
EXAMPLES
$ graphmysql serve ./graph.json 8086
See code: src/commands/serve/index.ts
We use https://github.com/sakiladb/mysql for testing purposes.
docker run -d -p 3306:3306 --name mysql-sakila sakiladb/mysql:5.7
npm run build
./bin/run.js explore sakila 127.0.0.1 'p_ssW0rd' sakila > graph.json
./bin/run.js serve ./graph.json 8086
./bin/run.js build ./graph.json > graph.html
if non-npm
npx oclif pack tarballs
via npm
npm version (major|minor|patch) # bumps version, updates README, adds git tag
npm publish