What does it do?
sqlallows you to pipe STDIN (hopefully containing SQL) to one or more pre-configured MySQL databases
- output comes out in
\t-separated format, allowing further piping (e.g. works really well with chart)
- when more than one database is queried, the requests are made in parallel
sqlcan either run
mysqllocally but connecting to a remote host (by configuring a
sshto a remote host and from there run
mysqlto either a local or remote host (by configuring an
Get the latest binary on the Releases section, or via
go get -u github.com/marianogappa/sql
Optionaly, you can install auto complete scripts for your shell too. It will complete the name of databases.
For bash, copy or link
sql-bash-autocomplete file to
For 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.
$ rm ~/.zcompdump $ compinit
cat query.sql | sql test_db sed 's/2015/2016/g' query_for_2015.sql | sql db1 db2 db3 sql all "SELECT * FROM users WHERE name = 'John'"
- when more than one database is queried, the resulting rows are prefixed with the database identifier
allspecial keyword means "sql to all configured databases"
sqlassumes that you have correctly configured SSH keys on all servers you
- please note that
~/.databases.jsonwill contain your database credentials in plain text; if this is a problem for you, don't use
sqlis meant for automation of one-time lightweight ad-hoc
SELECTs on many databases at once; it's not recommended for mission critical bash scripts that do destructive operations on production servers!
- If you close an ongoing
mysqlprocesses 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
- ssh (only if you configure an "appServer")