MySQL & Zombies

Wow your friends with this command-line tomfoolery: MySQL has a zombie mode!

It's really easy. First, a little bit about what you get in zombie mode:

-B is for "batch mode"

In batch mode, MySQL uses a vertical tab to separate columns of resulting data, instead of its fancy pipes-and-plus-signs table renderings.

So, instead of this:


+----+----------+---------------------------------------------------------------------+
| id | name     | notes                                                               |
+----+----------+---------------------------------------------------------------------+
|  1 | Werewolf | Also called a lycanthrope
Not as cool since the last Twilight movie |
|  2 | Zombie   | Ambling undead, of varying speeds     see also: zombie process          |
|  3 | Vampire  | NULL                                                                |
+----+----------+---------------------------------------------------------------------+

you'll get this:


id      name    notes
1       Werewolf        Also called a lycanthrope\nNot as cool since the last Twilight movie
2       Zombie  Ambling undead, of varying speeds\tsee also: zombie process
3       Vampire NULL

-r is for "raw output"

Zombies don't put much stock in presentation. Neither does MySQL, in raw mode. Special characters embedded in the data (like \t and \n) will be rendered literally, without backslash-escaping.

So, instead of this:


id      name    notes
1       Werewolf        Also called a lycanthrope\nNot as cool since the last Twilight movie
2       Zombie  Ambling undead, of varying speeds\tsee also: zombie process
3       Vampire NULL

you'll get this:


id      name    notes
1       Werewolf        Also called a lycanthrope
Not as cool since the last Twilight movie
2       Zombie  Ambling undead, of varying speeds       see also: zombie process
3       Vampire NULL

(note the literal newline in the first record; you know damn well the Zombies will).

-A disables autocomplete

Autocompletion of table and column names makes people faster. Zombies amble leisurely through undeath, and don't need to save any time.

-i ignores spaces

Keeps MySQL from being picky about where you put your whitespace in SQL queries. Zombies apparently can't type.

-N skips column names

You know what your data looks like. You don't need column names mucking up the carefully escaped (remember raw mode?) data and forcing you to strip off a line.


1       Werewolf        Also called a lycanthrope
Not as cool since the last Twilight movie
2       Zombie  Ambling undead, of varying speeds       see also: zombie process
3       Vampire NULL

-s is for silence

Aside from the occassional gurgle, Zombies are pretty quiet dudes (and dudettes). MySQL can be just as quiet, with this flag.

And Now, for the Punchline!

Put it all together, and whaddya get?

mysql -BrAiNs

James (@iamjameshunt) works on the Internet, spends his weekends developing new and interesting bits of software and his nights trying to make sense of research papers.

Currently working on Rook.