Tuesday, June 24, 2008

MySQL Pager = Vim

When using MySQL, you can set any pager you wish using the pager command.

mysq> pager less
PAGER set to 'less'

Using Vim as your pager allows you to quickly munge query output into whatever format you want.

mysql> pager vim -
PAGER set to 'vim -'

Thanks to Jay for the tip!


John Speno said...

I didn't know you could do paging in the mysql cli. Awesome!

mmarchin said...

Thanks, that's pretty handy. I usually would get by selecting into outfile, but this works well.

Anonymous said...

Just look for mysql pager info on: http://linux-sysadmin.org/2010/08/mysql-pager-filter-your-output/

Ayman Haidar said...

Great tip... You can put that in .my.cnf in your own directory. I also made slight modification to make vim start in read only mode and added nowrap so see the whole table without wrapping, it ended up like this in .my.cnf

pager = vim -R -c "set nowrap" -

I hope this helps somebody..