Alien::RRDtoolをhomebrew使わずに入れてみる

Alien::RRDtool - RRDtoolをCPANから入れる - Perl Advent Calendar Japan 2011 Hacker Trackを見て、実際に自分のMac(OS X 10.6.8)でRRDtoolを入れてみた。
素直にhomebrewで依存ライブラリ入れてしまえば問題無くインストール出来るのだけど、「homebrewとかに頼らずに全部自前ビルドするのが好き」という厨二気質を出してチャレンジしてみた。

環境

まっさらな状態を作るためにアカウントを新規に追加("hoge"とする)。"/Users/hoge/"以下だけで構築するよう頑張る。

Perlの準備

まずはperlbrew。

$ curl -kL http://xrl.us/perlbrewinstall | bash
$ echo 'source ~/.bashrc' >> ~/.bash_profile
$ echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bashrc
$ echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc 

5.14.2あたりを入れておく。

$ source ~/perl5/perlbrew/etc/bashrc
$ perlbrew install perl-5.15.2
$ perlbrew switch perl-5.14.2

cpanmを入れる。

$ curl -kL http://cpanmin.us | perl - App::cpanminus

いきなりインストールしてみる

$ cpanm -v Alien::RRDtool

...

Find 3rd-Party Libraries
checking for libdbi... no
checking for libwrap... no
checking for cairo_font_options_create in -lcairo... no
checking for pkg-config... no
configure: WARNING:
----------------------------------------------------------------------------
* I could not find a working copy of cairo-png. Check config.log for hints on why
  this is the case. Maybe you need to set LDFLAGS and CPPFLAGS appropriately
  so that compiler and the linker can find libcairo and its header files. If
  you have not installed cairo-png, you can get it either from its original home on

     http://cairographics.org/releases/

  You can find also find an archive copy on

     http://oss.oetiker.ch/rrdtool/pub/libs

  The last tested version of cairo-png is 1.4.6.

       LIBS=
   LDFLAGS=
  CPPFLAGS= -D_THREAD_SAFE

----------------------------------------------------------------------------

...

依存モジュール系を一通りインストールしてくれるが、その後でこういったメッセージで依存ライブラリが無いよ、と怒られる。親切ですね。

依存ライブラリを自力で入れる

適当にディレクトリ作ってそこで作業しつつ、$HOME/local以下にインストールしていく。

$ mkdir ~/temp

まずはpkg-config

$ cd ~/temp
$ curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-0.26.tar.gz
$ tar zxvf pkg-config-0.26.tar.gz 
$ cd pkg-config-0.26
$ ./configure --prefix=$HOME/local

なんか"glibが無い"って怒られた。それはこれから入れるのに…と思ってよく読んでみると

A copy of glib 1.2.10 is shipped together with pkg-config versions prior to 0.25

http://www.freedesktop.org/wiki/Software/pkg-config

0.25以下の方が入れやすそう。

$ cd ~/temp
$ curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-0.25.tar.gz
$ tar zxvf pkg-config-0.25.tar.gz 
$ cd pkg-config-0.25
$ ./configure --prefix=$HOME/local
$ make
$ make install

すんなり入った。次はcairo

$ cd ~/temp
$ curl -O http://oss.oetiker.ch/rrdtool/pub/libs/cairo-1.6.4.tar.gz
$ tar zxvf cairo-1.6.4.tar.gz 
$ cd cairo-1.6.4
$ ./configure --prefix=$HOME/local

pixmanが無い、と言われました。入れましょう。

$ cd ~/temp
$ curl -O http://oss.oetiker.ch/rrdtool/pub/libs/pixman-0.10.0.tar.gz
$ tar zxvf pixman-0.10.0.tar.gz 
$ cd pixman-0.10.0
$ ./configure --prefix=$HOME/local
$ make
$ make install

cairo再チャレンジ。

$ cd ~/temp/cairo-1.6.4
$ ./configure --prefix=$HOME/local

今度はlibpngが足りないそうです。入れる。

$ cd ~/temp
$ curl -O http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.18.tar.gz
$ tar zxvf libpng-1.2.18.tar.gz 
$ cd libpng-1.2.18
$ ./configure --prefix=$HOME/local
$ make
$ make install

どうだ。

$ cd ~/temp/cairo-1.6.4
$ ./configure --prefix=$HOME/local
$ make

...

cairo-quartz-font.c: In function 'cairo_quartz_font_face_create_for_cgfont':
cairo-quartz-font.c:247: warning: ignoring return value of '_cairo_error', declared with attribute warn_unused_result
cairo-quartz-font.c: In function '_cairo_quartz_init_glyph_metrics':
cairo-quartz-font.c:415: warning: unused variable 'textMatrix'
cairo-quartz-font.c: In function '_cairo_quartz_path_apply_func':
cairo-quartz-font.c:495: warning: ignoring return value of '_cairo_path_fixed_move_to', declared with attribute warn_unused_result
cairo-quartz-font.c:500: warning: ignoring return value of '_cairo_path_fixed_line_to', declared with attribute warn_unused_result
cairo-quartz-font.c:512: warning: ignoring return value of '_cairo_path_fixed_curve_to', declared with attribute warn_unused_result
cairo-quartz-font.c:522: warning: ignoring return value of '_cairo_path_fixed_curve_to', declared with attribute warn_unused_result
cairo-quartz-font.c:531: warning: ignoring return value of '_cairo_path_fixed_close_path', declared with attribute warn_unused_result
cairo-quartz-font.c: In function 'cairo_quartz_font_face_create_for_atsu_font_id':
cairo-quartz-font.c:781: error: implicit declaration of function 'FMGetATSFontRefFromFont'
cairo-quartz-font.c:781: warning: nested extern declaration of 'FMGetATSFontRefFromFont'
cairo-quartz-font.c:782: warning: 'CGFontCreateWithPlatformFont' is deprecated (declared at /System/Library/Frameworks/ApplicationServices.framework/Frameworks/CoreGraphics.framework/Headers/CGFont.h:60)
make[2]: *** [libcairo_la-cairo-quartz-font.lo] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

configureは出来るけどmakeでコケる。エラーメッセージでググると以下の記事が見つかった。
http://hwat.sakura.ne.jp/note/201001/20-220000/
20005 – Quartz font backend fails to compile
どうやらこのバージョンのcairoはイケてないらしい。このpatchが入ったあとのバージョンである1.8.8にしてみる。

$ cd ~/temp
$ curl -O http://cairographics.org/releases/cairo-1.8.8.tar.gz
$ tar zxvf cairo-1.8.8.tar.gz 
$ cd cairo-1.8.8
$ ./configure --prefix=$HOME/local

...

checking whether cairo's image surface backend feature could be enabled... no (requires pixman-1 >= 0.12.0 http://cairographics.org/releases/)
configure: error: mandatory image surface backend feature could not be enabled

おっと…そしたら今度はpixmanが古すぎてダメ orz。新しいの入れ直します。

$ cd ~/temp
$ curl -O http://cairographics.org/releases/pixman-0.12.0.tar.gz
$ tar zxvf pixman-0.12.0.tar.gz 
$ cd pixman-0.12.0
$ ./configure --prefix=$HOME/local
$ make
$ make install

今度こそ、と再挑戦

$ cd ~/temp/cairo-1.8.8
$ ./configure --prefix=$HOME/local
$ make

...

cairo-xlib-display.c:41:35: error: fontconfig/fontconfig.h: No such file or directory
make[3]: *** [cairo-xlib-display.lo] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

fontconfigが無い、と。

$ cd ~/temp
$ curl -O http://oss.oetiker.ch/rrdtool/pub/libs/fontconfig-2.4.2.tar.gz
$ tar zxvf fontconfig-2.4.2.tar.gz 
$ cd fontconfig-2.4.2
$ ./configure --prefix=$HOME/local
$ make
$ make install

これでどうだ…

$ cd ~/temp/cairo-1.8.8
$ ./configure --prefix=$HOME/local
$ make
$ make install

ようやくインストールできた。

次はglib

$ cd temp/
$ curl -O http://oss.oetiker.ch/rrdtool/pub/libs/glib-2.15.4.tar.gz
$ tar zxvf glib-2.15.4.tar.gz 
$ cd glib-2.15.4
$ ./configure --prefix=$HOME/local

...

checking libintl.h usability... no
checking libintl.h presence... no
checking for libintl.h... no
configure: error:
*** You must have either have gettext support in your C library, or use the
*** GNU gettext library. (http://www.gnu.org/software/gettext/gettext.html

gettextが必要です。入れる。

$ cd ~/temp
$ curl -O http://ftp.gnu.org/pub/gnu/gettext/gettext-0.18.1.1.tar.gz
$ tar zxvf gettext-0.18.1.1.tar.gz 
$ cd gettext-0.18.1.1
$ ./configure --prefix=$HOME/local
$ make
$ make install

再挑戦。

$ cd ~/temp/glib-2.15.4
$ ./configure --prefix=$HOME/local

どうもgettextpkg-configから情報を取ってこられない?自分でFLAGSを指定してやらないとうまくいかなかった。

$ ./configure --prefix=$HOME/local LDFLAGS="-L$HOME/local/lib" CPPFLAGS="-I$HOME/local/include"
$ make

...

gconvert.c:51:2: error: #error GNU libiconv not in use but included iconv.h is from libiconv
gconvert.c: In function 'g_convert_with_iconv':
gconvert.c:632: warning: format not a string literal and no format arguments
gconvert.c:669: warning: format not a string literal and no format arguments
gconvert.c: In function 'strdup_len':
gconvert.c:1017: warning: format not a string literal and no format arguments
gconvert.c: In function 'g_filename_to_uri':
gconvert.c:1893: warning: format not a string literal and no format arguments
make[4]: *** [gconvert.lo] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

configureは出来たけどまたmakeでコケる。libiconvが無かった。

$ cd ~/temp
$ curl -O http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
$ tar zxvf libiconv-1.14.tar.gz 
$ cd libiconv-1.14
$ ./configure --prefix=$HOME/local
$ make
$ make install

で再挑戦。

$ cd ~/temp/glib-2.15.4
$ ./configure --prefix=$HOME/local LDFLAGS="-L$HOME/local/lib" CPPFLAGS="-I$HOME/local/include"
$ make
$ make install

入った! 最後にpango

$ cd ~/temp
$ curl -O http://oss.oetiker.ch/rrdtool/pub/libs/pango-1.17.5.tar.gz
$ tar zxvf pango-1.17.5.tar.gz 
$ cd pango-1.17.5
$ ./configure --prefix=$HOME/local
$ make
$ make install

これはすんなり。

Alien::RRDtoolに挑戦

依存ライブラリが揃ったので、改めてAlien::RRDtoolのインストールをしてみる。

$ cpanm -v Alien::RRDtool

...

->> /Users/hoge/perl5/perlbrew/perls/perl-5.14.2/bin/perl Makefile.PL LIBS=-L/usr/local/lib -L/Developer/SDKs/MacOSX10.6.sdk/usr/lib -L/Developer/SDKs/MacOSX10.6.sdk/usr/X11/lib -lxml2 -lcairo -lcairo -lcairo  -lcairo -lpng12   -lglib-2.0 -lintl -liconv   -lpangocairo-1.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -lintl -liconv   RPATH=/Users/hoge/.cpanm/work/1323056803.27527/Alien-RRDtool-0.02/rrdtool/src/.libs
Checking if your kit is complete...
Looks good
'RPATH' is not a known MakeMaker parameter name.
Note (probably harmless): No library found for -lglib-2.0
Note (probably harmless): No library found for -lintl
Note (probably harmless): No library found for -lpangocairo-1.0
Note (probably harmless): No library found for -lpango-1.0
Note (probably harmless): No library found for -lgobject-2.0
Note (probably harmless): No library found for -lgmodule-2.0
Note (probably harmless): No library found for -lglib-2.0
Note (probably harmless): No library found for -lintl
Writing Makefile for RRDp
Writing MYMETA.yml
->> make
cp RRDp.pm blib/lib/RRDp.pm
Manifying blib/man3/RRDp.3
In rrdtool/bindings/perl-shared:
->> make test
PERL_DL_NONLAZY=1 /Users/hoge/perl5/perlbrew/perls/perl-5.14.2/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/base.t .. 1/7 Can't load '/Users/hoge/.cpanm/work/1323056803.27527/Alien-RRDtool-0.02/rrdtool/bindings/perl-shared/blib/arch/auto/RRDs/RRDs.bundle' for module RRDs: dlopen(/Users/hoge/.cpanm/work/1323056803.27527/Alien-RRDtool-0.02/rrdtool/bindings/perl-shared/blib/arch/auto/RRDs/RRDs.bundle, 2): Symbol not found: _g_free
  Referenced from: /Users/hoge/.cpanm/work/1323056803.27527/Alien-RRDtool-0.02/rrdtool/bindings/perl-shared/blib/arch/auto/RRDs/RRDs.bundle
  Expected in: dynamic lookup
 at t/base.t line 20
Compilation failed in require at t/base.t line 20.
BEGIN failed--compilation aborted at t/base.t line 20.
t/base.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 7/7 subtests 

Test Summary Report
-------------------
t/base.t (Wstat: 65280 Tests: 1 Failed: 1)
  Failed test:  1
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 7 tests but ran 1.
Files=1, Tests=1,  1 wallclock secs ( 0.03 usr  0.01 sys +  0.01 cusr  0.02 csys =  0.07 CPU)
Result: FAIL
Failed 1/1 test programs. 1/1 subtests failed.
make: *** [test_dynamic] Error 255
Failed to system(make test): No such file or directory at ./Build line 58
FAIL
! Installing Alien::RRDtool failed. See /Users/hoge/.cpanm/build.log for details.

ライブラリが足りない系のエラーは出ないけど、最後のビルドのところでNo library found for ...と言われて失敗している。LIBSで指定しているパスが足りていない…?
inc/MyBuilder.pmを見てみると、

    my @libdirs = (
        '/usr/local/lib',
        map { ("$_/usr/lib", "$_/usr/X11/lib") } </Developer/SDKs/MacOSX*>,
    );

    my $libs = do {
        open my $fh, '<', $self->notes('name') . '/Makefile';

        my $libs = '';
        while(<$fh>) {
            if(/ALL_LIBS \s+ = \s+ (.+) /xms) {
                chomp($libs = $1);
            }
        }
        join ' ', (map { "-L$_" } @libdirs),  $libs;
    };

    my $rpath = Cwd::abs_path($self->notes('name') . '/src/.libs') or die;

    $self->perl_bindings(sub {
        xsystem($self->perl,
            'Makefile.PL',
            "LIBS=$libs",
            "RPATH=$rpath");
        xsystem($Config{make});
    });

という指定になっていて、/usr/local/lib, /Developer/SDKs/MacOSX10.6.sdk/usr/lib, /Developer/SDKs/MacOSX10.6.sdk/usr/X11/libといったパスは入るけど、いままで自分でインストールしていた$HOME/local/libは含まれないことになる。
どうしたら良いのか分からないけど無理矢理書き加えてみた。

$ cd ~/temp
$ curl -LO http://search.cpan.org/CPAN/authors/id/G/GF/GFUJI/Alien-RRDtool-0.02.tar.gz
$ tar zxvf Alien-RRDtool-0.02.tar.gz
$ cd Alien-RRDtool-0.02
$ chmod u+w inc/MyBuilder.pm
$ vim inc/MyBuilder.pm

    my @libdirs = (
        '/Users/hoge/local/lib',
        '/usr/local/lib',
        map { ("$_/usr/lib", "$_/usr/X11/lib") } </Developer/SDKs/MacOSX*>,
    );

とダイレクトに指定。そうすると上手くいくようだ。

$ perl Build.PL
$ make
$ make test
$ make install
$ rrdtool 
RRDtool 1.4.5  Copyright 1997-2010 by Tobias Oetiker <tobi@oetiker.ch>
               Compiled Dec  6 2011 02:26:39

Usage: rrdtool [options] command command_options
Valid commands: create, update, updatev, graph, graphv,  dump, restore,
		last, lastupdate, first, info, fetch, tune,
		resize, xport, flushcached

RRDtool is distributed under the Terms of the GNU General
Public License Version 2. (www.gnu.org/copyleft/gpl.html)

For more information read the RRD manpages

結局

おそらくhomebrewなどのパッケージ管理ツールを使っていれば/usr/local/lib以下にライブラリが入るのでLIBSを書き換える必要ないと思うけど、自前でビルドして変なところにインストールしていると上手くいかない…のかな。
じゃあどうすれば良いのだろう?

$ pkg-config --libs-only-L cairo pango glib-2.0

の結果を$libsに足してもらうのが良いのかしら。

MySQLのコマンドたち

http://mysql-casual.org/2011/11/mysql-casual-advent-calendar-2011.html の6日目の記事として書かせていただきます、sugyanです。
勢いで参加表明してしまい、今日慌てて久しぶりにMySQLを触りました。

MySQLFizzBuzz

ストアドプロシージャって使ったこと無かったので初めて触ってみました。

DROP PROCEDURE IF EXISTS FizzBuzz;
delimiter //
CREATE PROCEDURE FizzBuzz(n INT)
BEGIN
    DECLARE i INT DEFAULT 1;
    WHILE i <= n DO
        SELECT CASE 
            WHEN i % 3 = 0 AND i % 5 = 0 THEN 'FizzBuzz' 
            WHEN i % 5 = 0 THEN 'Buzz' 
            WHEN i % 3 = 0 THEN 'Fizz'
            ELSE i
        END;
    SET i = i + 1;
    END WHILE;
END
//
CALL FizzBuzz(100);
DROP PROCEDURE FizzBuzz;
$ mysql -N -u root test < fizzbuzz.sql
1
2
Fizz
4
Buzz
Fizz
7
...

こんなカンジでMySQLでもカジュアルにFizzBuzzが出来るんですね!

本題

…というネタでやり過ごそうかと思っていましたが流石にアレなので、ちょっとリファレンスを読んだり過去のブクマを遡って便利そうなところを探したりしてみました。
で、目についたのがコチラ。
MySQL :: MySQL 5.5 Reference Manual :: 4.5.1.2 mysql Commands
mysqlのプロンプト上で使えるコマンド。って結構色々あるんですね。

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

このへんのコマンドたちって皆さんカジュアルに使いこなしているのでしょうか? 自分は結構知らなかったです。
幾つかおさらいしつつ紹介してみましょう。

clear

Clear the current input. Use this if you change your mind about executing the statement that you are entering.

よくクエリを途中まで打って「やっぱやめた」ってときに、ついCtrl-Cを押してしまってmysql自体を終了させてしまってたりしました。
そんなときは途中でも"\c"って打っておけば良かったんですね。

mysql> select hogefugapiyo\c
mysql> 

何事も無かったかのように次のプロンプトに流してくれます。
ていうか

$ mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 104
Server version: 5.5.15 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

ってmysql立ち上げたときに毎回出てきていたのに読んでなかった ><

ego

Send the current statement to the server to be executed and display the result using vertical format.

出力形式を縦に変えてくれるやつですね。これはたまに使ってました。

mysql> select * from fuga;
+----+------+
| id | name |
+----+------+
|  1 | foo  |
|  2 | bar  |
+----+------+
2 rows in set (0.00 sec)

mysql> select * from fuga\G
*************************** 1. row ***************************
  id: 1
name: foo
*************************** 2. row ***************************
  id: 2
name: bar
2 rows in set (0.00 sec)
status

Provide status information about the connection and the server you are using.

だそうで。

mysql> status;
--------------
mysql  Ver 14.14 Distrib 5.5.15, for osx10.6 (i386) using readline 5.1

Connection id:          106
Current database:       hoge
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.5.15 Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /tmp/mysql.sock
Uptime:                 2 hours 30 min 18 sec

Threads: 1  Questions: 11740  Slow queries: 0  Opens: 70  Flush tables: 3  Open tables: 25  Queries per second avg: 1.301
--------------

サクっと状態を確認できますね。

system

Execute the given command using your default command interpreter.

シェルコマンドをmysqlプロンプトから実行、と。"\!"でも代用可。

mysql> system ls ~/perl5/perlbrew
Config.pm       bin             build           build.log       dists           etc             perls
mysql> \! ls ~/perl5/perlbrew
Config.pm       bin             build           build.log       dists           etc             perls
warnings

Enable display of warnings after each statement (if there are any).

mysql> desc fuga;
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int(11)      | NO   | PRI | NULL    |       |
| name  | varchar(256) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> insert fuga (id) value ("piyo");
Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+----------------------------------------------------------+
| Level   | Code | Message                                                  |
+---------+------+----------------------------------------------------------+
| Warning | 1366 | Incorrect integer value: 'piyo' for column 'id' at row 1 |
+---------+------+----------------------------------------------------------+
1 row in set (0.00 sec)

普通こうやって参照しないと出てこないwarningsを、毎回出力してくれるようになる。

mysql> warnings
Show warnings enabled.
mysql> insert fuga (id) value ("piyo");
Query OK, 1 row affected, 1 warning (0.01 sec)

Warning (Code 1366): Incorrect integer value: 'piyo' for column 'id' at row 1
pager

Enable output paging.

結果出力時のpagerを指定できます。mysql起動時のコマンドラインオプション--pager、もしくはPAGER環境変数で指定しておくこともできるようです。
このあたりは下記記事で初めて知りました。
MySQL の pager が便利だった - xykの日記

mysql> pager less -n -i -S -F -X

と設定しておくと、見やすそうです。

※かるくlessオプションのおさらい:

  • "-n": 行表示抑制
  • "-i": 検索時の大文字小文字無視
  • "-S": 折り返し抑制
  • "-F": 一画面内に表示が収まる場合は表示して終了
  • "-X": less終了時に画面クリアさせない
prompt

Reconfigure the mysql prompt to the given string.

デフォルトではmysql> と表示されるプロンプトを変更できます。下記記事が詳しいかと思います。
漢(オトコ)のコンピュータ道: MySQLのプロンプトを変更する。

mysql> prompt \D \U \p [\d] >\_
PROMPT set to '\D \U \p [\d] >\_'
Tue Dec  6 19:53:21 2011 root@localhost mysql.sock [hoge] > 

こんなカンジで設定したりすると、現在時刻とユーザ名、TCP/IPポート or ソケットファイル名、使用中のデータベース、をすべてプロンプトに表示されますね。年、月、時、分、秒、は個別に取れるけど、「日」が取れないっぽい…何故。。ソースまで覗いてみたけどそれ用のspecial sequenceは定義されていないようでした。不思議…。
これも、mysql起動時の--promptオプションや、MYSQL_PS1環境変数、さらに/etc/my.cnfなどの設定ファイルで

[mysql]
prompt=(\\u@\\h) [\\d]>\\_

のように設定しておくこともできるようです。

quit

おしまい。