この記事は MySQL Casual Advent Calendar 2014の10日目の記事で、7日目の記事 grcでMySQLのクエリ結果に色を付ける へのアンサーエントリーです :)
MySQL 5.6.12から、mysqlコマンドラインクライアントが使うデフォルトのreadlineが、フツーの(?) readlineからMySQLにバンドルされているreadlineに変わっています。そのため、MYSQL_PS1(や--prompt)にecho -eの出力結果を食わせてやろうとすると
こうなります。
や、MySQLにバンドルされているやつと、システムワイドでインストールされてるやつでどうreadlineの実装が違うのとか全く興味がないので本当にreadlineのせいかどうかと聞かれると若干困るんですが、システムワイドのreadlineを使うようにしてmakeするとちゃんとこれを解釈できるようになるのでたぶんMySQLにバンドルされているreadlineのせいです(長)
なおゲスい話ではありますが、接続してるのがマスターかスレーブか、ユーザーはrootか否かとかで更に色を出しわけたりできるので、わたしはmysqlコマンドラインクライアントにパッチをするのも好きです :)
Have fun!!
MySQL 5.6.12から、mysqlコマンドラインクライアントが使うデフォルトのreadlineが、フツーの(?) readlineからMySQLにバンドルされているreadlineに変わっています。そのため、MYSQL_PS1(や--prompt)にecho -eの出力結果を食わせてやろうとすると
$ export MYSQL_PS1=$(echo -e "\e[1;33mmysql[\d]\e[0m\n> ")
$ client/mysql -S /usr/mysql/5.6.22/data/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.22-log Source distribution
Copyright (c) 2000, 2014, 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.
1;33mmysql[(none)[0>
1;33mmysql[(none)[0>
1;33mmysql[(none)[0> ^DBye
こうなります。
や、MySQLにバンドルされているやつと、システムワイドでインストールされてるやつでどうreadlineの実装が違うのとか全く興味がないので本当にreadlineのせいかどうかと聞かれると若干困るんですが、システムワイドのreadlineを使うようにしてmakeするとちゃんとこれを解釈できるようになるのでたぶんMySQLにバンドルされているreadlineのせいです(長)
$ sudo yum install libedit-devel
$ cmake -DWITH_EDITLINE=system .
$ make mysql
$ export MYSQL_PS1=$(echo -e "\e[1;33mmysql[\d]\e[0m\n> ")
$ client/mysql -S /usr/mysql/5.6.22/data/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.22-log Source distribution
Copyright (c) 2000, 2014, 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[(none)]
>
なおゲスい話ではありますが、接続してるのがマスターかスレーブか、ユーザーはrootか否かとかで更に色を出しわけたりできるので、わたしはmysqlコマンドラインクライアントにパッチをするのも好きです :)
Have fun!!