Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sethblack/mysql-to-json
Connects to a MySQL database and exports selected data to JSON.
https://github.com/sethblack/mysql-to-json
command-line command-line-tool json mysql mysql-json python python-3 python-script python3
Last synced: 30 days ago
JSON representation
Connects to a MySQL database and exports selected data to JSON.
- Host: GitHub
- URL: https://github.com/sethblack/mysql-to-json
- Owner: sethblack
- License: bsd-2-clause
- Created: 2018-02-13T22:56:07.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-02-24T19:58:53.000Z (over 4 years ago)
- Last Synced: 2024-10-07T19:08:48.732Z (about 1 month ago)
- Topics: command-line, command-line-tool, json, mysql, mysql-json, python, python-3, python-script, python3
- Language: Python
- Size: 6.84 KB
- Stars: 22
- Watchers: 5
- Forks: 9
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mysql-to-json
Connects to a MySQL database and exports selected data to JSON.
## Installation
```
$> pip3 install mysql-to-json
```## Usage
```
mysql-to-json [-h] [-d DATABASE] [-H HOSTNAME] [-P PORT] [-u USER] [-p]
[-e QUERY]optional arguments:
-h, --help show this help message and exit
-d DATABASE, --database DATABASE
MySQL database name.
-H HOSTNAME, --hostname HOSTNAME
MySQL host name.
-P PORT, --port PORT MySQL port number.
-u USER, --user USER MySQL username.
-p, --password Shh! It's a secret.
-e QUERY, --query QUERY
Query to run.
```## Examples
All examples simple select all table information from `information_schema` and save it to `tables.json`
### Simple
This assumes we have full access to the mysql database from localhost.
```
$> mysql-to-json -e 'SELECT * FROM information_schema.tables' > tables.json
```### Medium Complexity
This explicitly sets a user and asks for a password, while still connecting to localhost.
```
$> mysql-to-json -d mysql -u seth -p -e 'SELECT * FROM information_schema.tables' > tables.json
```### All The Things!
This explicitly sets every command line option available.
```
$> mysql-to-json -h mydbserver.myhost.com -P 3306 -d mysql -u seth -p -e 'SELECT * FROM information_schema.tables' > tables.json
```### All The Things without prompt access
This explicitly sets every command line option available and uses password stored in variable `$MYSQL_PASSWORD`.
```
$> echo $MYSQL_PASSWORD | mysql-to-json -h mydbserver.myhost.com -P 3306 -d mysql -u seth -p -e 'SELECT * FROM information_schema.tables' > tables.json
```