Quite often, I’ll find myself wanting to query and manipulate MySQL data entirely on the command line. I could be building up a pipeline or working on a task that I’m going to eventually automate but haven’t quite gotten to yet. Whenver I have to do something like that, I have a small pile of scripts I’ve written over time that help out:
skiphead
: Skip the first line of output, used to skip over headers in a query responseskipuntil
: Skip all lines until we see one matching a pattern, used to resume partial taskscommaify
: Take a list of single values on the command line and turn them into a comma separated list (for use inIN
clauses)csv2json
: a previously posted script for converting csv/tab delimited output to jsonjq
: not my script, but used to take the output of csv2json and query it further in ways that would be complicated to do with SQL
Admitedly, the first two of those are one liners and I could easily remember them, but the advantage of a single command that does it is tab completion. sk<tab>
, arrow to select which one I want, and off we go. I could put them as an alias, but I don’t always use the same shell (mostly fish, but sometimes Bash or Zsh).