«

»

Jul 30

MySQL CLI pager tweaks

The default settings for the MySQL command line client are a bit annoying. There’s no output paging; columns with more than 80 characters are wrapped making matching field name to field data difficult. Here’s a way to make life easier.

Reference: http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html (and from the comments therein)

You can set the PAGER variable several ways. In the following examples, I’m setting it to “less -niSFX”. Note that you must have “less” installed for this to work, and, according to the reference above, this doesn’t work on Win32, but you shouldn’t be running mysql on Win32 anyway ;).

In my.cnf (either in your home directory, or the system-wide file, whose location depends on your distribution):

[mysql]
pager=less -niSFX

From the shell:

$ mysql --pager="less -niSFX"

From within the mysql command line client:

mysql> pager less -niSFX

I haven’t yet found a way to set the pager behavior back to the default (i.e. no output paging) from the CLI prompt, so you’ll have to exit the CLI, remove these my.cnf changes or options from the command line and re-execute the client. I’ll edit this to reflect any new info.

1 comment

  1. Jesse

    On the mysql client command line, you can turn off the pager by typing “nopager”. To still use “less” (the default, with no options), just type “pager less”.

    Thanks to my coworker Yaniv for figuring that one out! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


Clef two-factor authentication