MySQL pager configuration

Have you ever typed in a SQL query that returns thousands and thousands of results, and you had to Ctrl-C to stop it, which would then also terminate your MySQL console process? Annoying, isn’t it!

Well, there is actually a pager configuration for MySQL. My favorite pager is less, ’cause less is more, right? Paradoxically, it has more features than more, for in more you wouldn’t be able to scroll up, for example.

To make MySQL use less as the pager, you should add the following line to your my.cnf file, in the [client] block:

[client]
pager = "less -X -F"

Here is what the arguments do:

  • -X: prevent less from clearing the screen when exiting. This is useful when you want to have the results on screen after quitting less, to be able to compose your next SQL command
  • -F: tells less to quit immediately if the buffer fits on one screen. Without this, you’d have to quit less first before you can type the next SQL command, even though it fitted perfectly on one screen.

What are your thoughts?