https://github.com/reiniiriarios/run-queries
Small bash script to run SQL queries on remote server and generate CSV files. Useful for commonly run queries that need to be handed off, such as for QA.
https://github.com/reiniiriarios/run-queries
bash bash-script mariadb mysql ssh
Last synced: 2 months ago
JSON representation
Small bash script to run SQL queries on remote server and generate CSV files. Useful for commonly run queries that need to be handed off, such as for QA.
- Host: GitHub
- URL: https://github.com/reiniiriarios/run-queries
- Owner: reiniiriarios
- License: gpl-3.0
- Created: 2021-03-12T02:09:18.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-12T02:41:04.000Z (over 5 years ago)
- Last Synced: 2025-10-11T12:47:02.985Z (9 months ago)
- Topics: bash, bash-script, mariadb, mysql, ssh
- Language: Shell
- Homepage:
- Size: 15.6 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# run-queries
Small bash script to run MySQL queries on over SSH and generate CSV files. Useful for QA where queries need to be run repeatedly and CSV files handed off, to be imported elsewhere or easily opened in Excel or another spreadsheet application.
## Configuration
`mv config.example.sh config.sh`
Fill in all login information:
* Path to SSH private key
* SSH username
* SSH host
* MySQL/MariaDB username
* MySQL/MariaDB password
* MySQL/MariaDB host (usually 127.0.0.1 or localhost)
* MySQL/MariaDB database name
*This script only works with SSH private keys.*
## Usage
Add `.sql` files to the `sql/` directory.
`./run-query.sh`
The script will list all available queries. Enter which query to run by number. After running the query, a timestamped CSV will be in `csv/` and a corresponding TSV in `tsv/`.
## Known Issues
* This script will break if double quotes or backticks are used in `.sql` files.
* Depending on data being fetched, the script may not generate a valid CSV. If so, try the TSV or adjust the query as needed.