Posts Tagged ‘mysql tricks’

MySQL Pager

Friday, July 10th, 2009

The pager command in mysql is pretty cool. When you use it, anything you type on the mysql command line is piped thru what you set it to. Here's one I use often, especially when load is high and/or replication starts to get behind.

mysql> pager grep -v "Sleep" |sort -n -t "|" -k 7 |tail -5
PAGER set to 'grep -v "Sleep" |sort -n -t "|" -k 7 |tail -5'
mysql> show processlist;

Now the process list is stripped of any sleeping processes and shows the 5 oldest ones.

You could also use pager to pipe your output thru a script. Leave a comment if you have a useful one.