{"id":13581821,"url":"https://github.com/marianogappa/sql","last_synced_at":"2025-07-11T16:12:28.240Z","repository":{"id":54175765,"uuid":"68439276","full_name":"marianogappa/sql","owner":"marianogappa","description":"MySQL \u0026 PostgreSQL pipe","archived":false,"fork":false,"pushed_at":"2022-07-22T01:11:52.000Z","size":644,"stargazers_count":86,"open_issues_count":3,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T22:58:16.643Z","etag":null,"topics":["cli","mysql","postgres","postgresql","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marianogappa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-17T07:52:21.000Z","updated_at":"2023-05-22T17:17:57.000Z","dependencies_parsed_at":"2022-08-13T08:20:49.122Z","dependency_job_id":null,"html_url":"https://github.com/marianogappa/sql","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/marianogappa/sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marianogappa%2Fsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marianogappa%2Fsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marianogappa%2Fsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marianogappa%2Fsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marianogappa","download_url":"https://codeload.github.com/marianogappa/sql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marianogappa%2Fsql/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264850641,"owners_count":23673232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","mysql","postgres","postgresql","sql"],"created_at":"2024-08-01T15:02:15.689Z","updated_at":"2025-07-11T16:12:28.183Z","avatar_url":"https://github.com/marianogappa.png","language":"Go","readme":"# sql [![Build Status](https://img.shields.io/travis/marianogappa/parseq.svg)](https://travis-ci.org/marianogappa/parseq) [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/MarianoGappa/sd/master/LICENSE)\n\nMySQL pipe\n\n![SQL](sql.gif)\n\n[Blogpost](https://movio.co/en/blog/improving-with-sql-and-charts/)\n\n## What does it do?\n\n- `sql` allows you to pipe STDIN (hopefully containing SQL) to one or more pre-configured MySQL or PostgreSQL databases\n- output comes out in `\\t`-separated format, allowing further piping (e.g. works really well with [chart](https://github.com/MarianoGappa/chart))\n- when more than one database is queried, the requests are made in parallel\n- `sql` can either run `mysql/psql` locally, run `mysql/psql` locally but connecting to a remote host (by configuring a `dbServer`), or `ssh` to a remote host and from there run `mysql/psql` to either a local or remote host (by configuring an `appServer` and a `dbServer`)\n\n## Installation\n\nGet the latest binary on the [Releases](https://github.com/MarianoGappa/sql/releases) section, or via `go get`:\n```\ngo get -u github.com/marianogappa/sql\n```\n\n### Auto completion\n\nOptionaly, you can install auto complete scripts for your shell too. It will complete the name of databases.\n\nFor bash, copy or link `sql-bash-autocomplete` file to `/etc/bash_completion.d` directory.\n\nFor zsh, copy or link `sql-zsh-autocomplete` file to somewhere in your `$fpath`. (If you use oh-my-zsh framework, copy/link it to `~/.oh-my-zsh/completions`.) Note that file should be renamed to `_sql`. You may also need to run the following commands in order to force ZSH to rebuild its auto completion cache.\n\n```\n$ rm ~/.zcompdump\n$ compinit\n```\n\n## Configuration\n\nCreate a `.databases.json` dotfile in your home folder or in any [XDG-compliant](https://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html) directory. [This](.databases.json.example) is an example file.\n\n`sql` decides to execute with MySQL or PostgreSQL depending on the `sqlType` property set for a database, *defaulting to to MySQL if not set.*\n\n## Example usages\n\n```\ncat query.sql | sql test_db\n\nsed 's/2015/2016/g' query_for_2015.sql | sql db1 db2 db3\n\nsql all \"SELECT * FROM users WHERE name = 'John'\"\n```\n\n## Notes\n\n- when more than one database is queried, the resulting rows are prefixed with the database identifier\n- the `all` special keyword means \"sql to all configured databases\".\n- `sql` assumes that you have correctly configured SSH keys on all servers you `ssh` to\n- `sql` will error if all targeted databases do not have the same sql type.\n\n## Beware!\n\n- please note that `~/.databases.json` will contain your database credentials in plain text; if this is a problem for you, don't use `sql`!\n- `sql` is meant for automation of one-time lightweight ad-hoc `SELECT`s on many databases at once; it's not recommended for mission critical bash scripts that do destructive operations on production servers!\n- If you close an ongoing `sql` operation, spawned `mysql` and `ssh`-\u003e`mysql` processes will soon follow to their deaths, but the underlying mysql server query thread will complete, as long as it takes! https://github.com/marianogappa/sql/issues/7\n\n## Dependencies\n\n- mysql-client and/or postgresql-client\n- ssh (only if you configure an \"appServer\")\n\n## Contribute\n\nIf you have an issue with sql, I'd love to [hear about it](https://github.com/marianogappa/sql/issues/new). PRs are welcome. Ping me on [Twitter](https://twitter.com/MarianoGappa) if you want to have a chat about it.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarianogappa%2Fsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarianogappa%2Fsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarianogappa%2Fsql/lists"}