Question

I've just discovered the pager command in the MySQL command-line client, and I'm having a tonne of fun. This blog post is great:

http://www.mysqlperformanceblog.com/2008/11/21/how-to-calculate-a-good-innodb-log-file-size/

Unfortunately as a Perl programmer I find myself wanting to do more and more complicated pagers, and I've hit into a problem: I don't seem to be able to use a semicolon character in my pager command.

Simple:

mysql> pager md5sum
PAGER set to 'md5sum'
mysql> select id from listings limit 5;
cfbe10c0a46ea57f6fa199bc9e05ed3a  -

More complicated but still fine:

mysql> pager perl -nle 'print "    $_"'
PAGER set to 'perl -nle 'print "    $_"''
mysql> select id from listings limit 5;
    +---------+
    | id      |
    +---------+
    | 2003921 |
    | 7164746 |
    | 7166576 |
    | 7166605 |
    | 7166853 |
    +---------+

(That one is useful for dealing with Markdown!)

But unfortunately if I add a semicolon on the end of my statement it says I have a syntax error:

mysql> pager perl -nle 'print "    $_";'
    -> \c

mysql> pager perl -nle 'print "    $_";';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'pager perl -nle 'print "    $_";'' at line 1

I've tried escaping the semicolon in the Perl command with a backslash or two (in case the backslash itself needed escaping) but nothing seems to work.

Is it possible to include a semicolon in a pager command?

Was it helpful?

Solution

Try to set delimiter to something else than ;

     mysql> DELIMITER endl
     mysql>

Then you can set pager with the semicolon:

     mysql> pager pager perl -nle 'print "    $_";'endl
     PAGER set to 'pager perl -nle 'print "    $_";''

Then you can come back to ;

     mysql> DELIMITER ;
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange
scroll top