Paginating Your Results
Many times your results are longer than your screen. You end up scrolling up the terminal screen. It can be a pain. One way to solve this problem was shown to me some months ago in a session and it kind of slid right by me (maybe I should have scrolled up the screen :))
I just came across it again and thought I would document it for both me and anyone who hasn’t heard of this. It is quite useful. All you have to do is this:
mysql> \P less
PAGER set to ‘less’
Then, when your results hit the bottom of the screen, you will get a colon prompt and it will wait for you to hit any key. Once you hit the end the prompt changes to (END). Hitting the ‘q’ key will return you to the normal mysql> prompt. It can be very useful. Enjoy!!
6 Comments so far
Leave a reply
Thank you, that’s wonderful!
is there a way to set it so that I don’t have to type “\P less” at the start of every mysql session? (Is there something like a .mysql conf file?)
Thanks!
Not that I am aware of. However, fyi, there is a .my.cnf file that you can create in your home directory for things such as username and password.
And in case you want to switch back and forth, “\P stdout” will set the output back to normal. Simply \P will work as well, since stdout is the default.
Looking at the documentation, there’s actually a lot of interesting stuff one can do. Since you are essentially passing it unix commands (like \P cat) you can add in command line options and output redirects. For example “\P cat > output.txt” sends all the output to a text file (in the directory you were in when you started mysql).
Full documentation is here: http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html
Put this in your ~/.my.cnf
[mysql]
pager=less
Perfect Jan. Thanks.