<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Neat tricks for the MySQL command-line pager</title>
	<atom:link href="http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/</link>
	<description>Everything about MySQL Performance</description>
	<pubDate>Thu, 20 Nov 2008 14:33:22 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Parvesh Garg</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-324903</link>
		<dc:creator>Parvesh Garg</dc:creator>
		<pubDate>Tue, 08 Jul 2008 16:55:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-324903</guid>
		<description>Check my post http://optimmysql.blogspot.com/2008/07/mysql-command-line-pager-mysmartpager.html for a small hack that can do regex based paging.</description>
		<content:encoded><![CDATA[<p>Check my post <a href="http://optimmysql.blogspot.com/2008/07/mysql-command-line-pager-mysmartpager.html" rel="nofollow">http://optimmysql.blogspot.com/2008/07/mysql-command-line-pager-mysmartpager.html</a> for a small hack that can do regex based paging.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Javier Tacón</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-317552</link>
		<dc:creator>Javier Tacón</dc:creator>
		<pubDate>Wed, 25 Jun 2008 09:59:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-317552</guid>
		<description>pager less -niSFX</description>
		<content:encoded><![CDATA[<p>pager less -niSFX</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Lowe</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-317405</link>
		<dc:creator>Ryan Lowe</dc:creator>
		<pubDate>Wed, 25 Jun 2008 04:35:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-317405</guid>
		<description>gah.  The scrubber changed:

while ( my $line = &#60;STDIN&#62;)

to

while ( my $line = )</description>
		<content:encoded><![CDATA[<p>gah.  The scrubber changed:</p>
<p>while ( my $line = &lt;STDIN&gt;)</p>
<p>to</p>
<p>while ( my $line = )</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ryan Lowe</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-317404</link>
		<dc:creator>Ryan Lowe</dc:creator>
		<pubDate>Wed, 25 Jun 2008 04:34:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-317404</guid>
		<description>I use pager for two things:

1) Save the results of the last query
2) Replace EXPLAIN with mk-visual-explain

Unfortunately, MySQL 5.0.51a and earlier writes to the tee file AFTER the pager has completed (and to .mysql_history only after you exit mysql), so getting the last command is impossible via these methods (however, it works if you are willing to issue queries twice ...).  You *can* still override commands (EXPLAIN, for example) by having scripts that error if the input does not conform to a standard; an example follows:

#!/usr/bin/perl

use strict;
use warnings FATAL =&#62; 'all';
use English qw ( -no_match_vars );

my $out;

while ( my $line =  ) {

$out .= $line;

}

# Log results to a file (always useful)
# But only ever save one :)
open (PAGER_LOG, '&#62;/tmp/mysql_pager.log');
print PAGER_LOG "$out\n";
close (PAGER_LOG);

# See if it an EXPLAIN
eval { local $SIG{'__WARN__'}; system('/usr/local/bin/mk-visual-explain /tmp/mysql_pager.log 2&#62; /dev/null'); };

if ($?) {

  print $out;

}</description>
		<content:encoded><![CDATA[<p>I use pager for two things:</p>
<p>1) Save the results of the last query<br />
2) Replace EXPLAIN with mk-visual-explain</p>
<p>Unfortunately, MySQL 5.0.51a and earlier writes to the tee file AFTER the pager has completed (and to .mysql_history only after you exit mysql), so getting the last command is impossible via these methods (however, it works if you are willing to issue queries twice &#8230;).  You *can* still override commands (EXPLAIN, for example) by having scripts that error if the input does not conform to a standard; an example follows:</p>
<p>#!/usr/bin/perl</p>
<p>use strict;<br />
use warnings FATAL =&gt; &#8216;all&#8217;;<br />
use English qw ( -no_match_vars );</p>
<p>my $out;</p>
<p>while ( my $line =  ) {</p>
<p>$out .= $line;</p>
<p>}</p>
<p># Log results to a file (always useful)<br />
# But only ever save one <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /><br />
open (PAGER_LOG, &#8216;&gt;/tmp/mysql_pager.log&#8217;);<br />
print PAGER_LOG &#8220;$out\n&#8221;;<br />
close (PAGER_LOG);</p>
<p># See if it an EXPLAIN<br />
eval { local $SIG{&#8217;__WARN__&#8217;}; system(&#8217;/usr/local/bin/mk-visual-explain /tmp/mysql_pager.log 2&gt; /dev/null&#8217;); };</p>
<p>if ($?) {</p>
<p>  print $out;</p>
<p>}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clint Byrum</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-317309</link>
		<dc:creator>Clint Byrum</dc:creator>
		<pubDate>Tue, 24 Jun 2008 23:39:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-317309</guid>
		<description>Parvesh, you can have your cake and eat it too.

superpager.bash:


#!/bin/bash
teefile=~/.mysqltee

goback=100

# find the last ^mysql&#62;

lastcmd=$(tail -n $goback $teefile &#124; grep "^mysql&#62; "&#124;tail -1&#124; awk -F"mysql&#62; " '{print $2}'&#124;sed -e 's/\*/\\*/g')

echo lastcmd=$lastcmd

if echo "$lastcmd" &#124; egrep -qi "^\s*explain" ; then
  exec mk-visual-explain
fi
if echo "$lastcmd" &#124; egrep -qi "^\s*show\s+engine" ; then
  fgrep -C3 -i "LOCK" &#124; less
  exit
fi
less

One has to do a \T ~/.mysqltee before the \P superpager.bash , but thats nice because everything you do gets logged..

Works reasonably well for something I hacked together with bash in 10 minutes. Would be nice if the pager could be passed args like "last command" but this is a decent enough hack until they implement that in version 6.1 of mysql. ;)</description>
		<content:encoded><![CDATA[<p>Parvesh, you can have your cake and eat it too.</p>
<p>superpager.bash:</p>
<p>#!/bin/bash<br />
teefile=~/.mysqltee</p>
<p>goback=100</p>
<p># find the last ^mysql&gt;</p>
<p>lastcmd=$(tail -n $goback $teefile | grep &#8220;^mysql&gt; &#8220;|tail -1| awk -F&#8221;mysql&gt; &#8221; &#8216;{print $2}&#8217;|sed -e &#8217;s/\*/\\*/g&#8217;)</p>
<p>echo lastcmd=$lastcmd</p>
<p>if echo &#8220;$lastcmd&#8221; | egrep -qi &#8220;^\s*explain&#8221; ; then<br />
  exec mk-visual-explain<br />
fi<br />
if echo &#8220;$lastcmd&#8221; | egrep -qi &#8220;^\s*show\s+engine&#8221; ; then<br />
  fgrep -C3 -i &#8220;LOCK&#8221; | less<br />
  exit<br />
fi<br />
less</p>
<p>One has to do a \T ~/.mysqltee before the \P superpager.bash , but thats nice because everything you do gets logged..</p>
<p>Works reasonably well for something I hacked together with bash in 10 minutes. Would be nice if the pager could be passed args like &#8220;last command&#8221; but this is a decent enough hack until they implement that in version 6.1 of mysql. <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: PaulM</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-317049</link>
		<dc:creator>PaulM</dc:creator>
		<pubDate>Tue, 24 Jun 2008 11:32:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-317049</guid>
		<description>This is one I use a bit, requires a Unix/Linux OS though. You could do similar on MySQL on Windows.

pager grep -v "Sleep" &#124;sort -n -t "&#124;" -k 7 &#124;tail

show processlist will now suppress sleeping sessions and display the top 10 oldest sessions.

Thanks for the tip on passing any script... very nice. I have interesting tests to try out... or just use mytop eh?

Have Fun

Paul</description>
		<content:encoded><![CDATA[<p>This is one I use a bit, requires a Unix/Linux OS though. You could do similar on MySQL on Windows.</p>
<p>pager grep -v &#8220;Sleep&#8221; |sort -n -t &#8220;|&#8221; -k 7 |tail</p>
<p>show processlist will now suppress sleeping sessions and display the top 10 oldest sessions.</p>
<p>Thanks for the tip on passing any script&#8230; very nice. I have interesting tests to try out&#8230; or just use mytop eh?</p>
<p>Have Fun</p>
<p>Paul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parvesh Garg</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-317033</link>
		<dc:creator>Parvesh Garg</dc:creator>
		<pubDate>Tue, 24 Jun 2008 09:42:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-317033</guid>
		<description>This is cool. I have known (and ignored) this earlier, my bad. But something with mk-visual-explain (one of my favorite tools) is just great.

Next, I would like to see some regex based piping that I can specify in my.cnf, something like 

pager ^explain = mk-visual-explain
pager ^show engine = less
pager .* = stdout 

I dont think I'm asking too much :)

--
Parvesh</description>
		<content:encoded><![CDATA[<p>This is cool. I have known (and ignored) this earlier, my bad. But something with mk-visual-explain (one of my favorite tools) is just great.</p>
<p>Next, I would like to see some regex based piping that I can specify in my.cnf, something like </p>
<p>pager ^explain = mk-visual-explain<br />
pager ^show engine = less<br />
pager .* = stdout </p>
<p>I dont think I&#8217;m asking too much <img src='http://www.mysqlperformanceblog.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>&#8211;<br />
Parvesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Giuseppe Maxia</title>
		<link>http://www.mysqlperformanceblog.com/2008/06/23/neat-tricks-for-the-mysql-command-line-pager/#comment-316993</link>
		<dc:creator>Giuseppe Maxia</dc:creator>
		<pubDate>Tue, 24 Jun 2008 05:38:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.mysqlperformanceblog.com/?p=420#comment-316993</guid>
		<description>Cool tricks. My most frequent usage of "pager" is "vim -" and then manipulate the output at will.

I have a handy script that gives me the size of indexes in a database from a SHOW TABLE STATUS. (Useful when you need to calculate how much memory to allocate for a buffer).

$ cat index_size.sh 
perl -lane '$i+= $F[17];END{print $i}' 

mysql&#62; pager ./index_size.sh
PAGER set to './index_size.sh'
mysql&#62; show table status;
71680

mysql&#62; nopager


Giuseppe</description>
		<content:encoded><![CDATA[<p>Cool tricks. My most frequent usage of &#8220;pager&#8221; is &#8220;vim -&#8221; and then manipulate the output at will.</p>
<p>I have a handy script that gives me the size of indexes in a database from a SHOW TABLE STATUS. (Useful when you need to calculate how much memory to allocate for a buffer).</p>
<p>$ cat index_size.sh<br />
perl -lane &#8216;$i+= $F[17];END{print $i}&#8217; </p>
<p>mysql&gt; pager ./index_size.sh<br />
PAGER set to &#8216;./index_size.sh&#8217;<br />
mysql&gt; show table status;<br />
71680</p>
<p>mysql&gt; nopager</p>
<p>Giuseppe</p>
]]></content:encoded>
	</item>
</channel>
</rss>
