Configure mariadb client prompt

Configure mariadb client prompt

基本的にDBに直接入ることは無いけど、せっかくなので(?)プロンプトをカスタマイズしてみる。デフォルト状態だとこんな感じ。

MariaDB [(none)]>

ライブで変更するにはPROMPTコマンドを実行する。

MariaDB [(none)]> PROMPT \U [\d] \r:\m \P>\_
PROMPT set to '\U [\d] \r:\m \P>\_'
lorentzca@localhost [(none)] 10:21 pm>

PROMPT単体で実行すると、初期状態に戻るので、試しながら気に入ったプロンプト探すのがよさ気。

lorentzca@localhost [(none)] 10:21 pm> PROMPT
Returning to default PROMPT of \N [\d]>
MariaDB [(none)]>

ハイパーもりもりプロンプト

MariaDB [(none)]> PROMPT \c \D \d \h \l \m \n \O \P \p \r \S \s \t \U \v \w \Y \_>\_
PROMPT set to '\c \D \d \h \l \m \n \O \P \p \r \S \s \t \U \v \w \Y \_>\_'
1 Wed Aug 24 22:30:10 2016 (none) localhost ; 30
 Aug pm mysql.sock 10 ; 10       lorentzca@localhost 5.5.47-MariaDB Wed 2016  >

\U\_などのシーケンスについては以下にまとまっている。

永続化する

気に入ったプロンプトが見つかったら、デフォルトでそのプロンプトが適用されるようにしてみる。centos7でyum install mariadb-serverした場合は設定ファイルは以下のようなツリーになっている。

/etc/my.cnf
/etc/my.cnf.d/
├── client.cnf
├── mysql-clients.cnf
└── server.cnf

clientの設定らしきものが2つ...。提供元パッケージが違うっぽい。

$ rpm -ql mariadb-server | grep '/etc/my.cnf.d'
/etc/my.cnf.d/server.cnf

$ rpm -ql mariadb | grep '/etc/my.cnf.d'
/etc/my.cnf.d/client.cnf

$ rpm -ql mariadb-libs | grep '/etc/my.cnf.d'
/etc/my.cnf.d
/etc/my.cnf.d/mysql-clients.cnf

どっち使えばいいんじゃろ。とりあえず中身見てみる。

client.cnf

#
# These two groups are read by the client library
# Use it for options that affect all clients, but not the server
#


[client]

# This group is not read by mysql client library,
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]

mysql-clients.cnf

#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#

[mysql]

[mysql_upgrade]

[mysqladmin]

[mysqlbinlog]

[mysqlcheck]

[mysqldump]

[mysqlimport]

[mysqlshow]

[mysqlslap]

どっちでもいいっぽい。[client]もしくは[client-mariadb]に設定すれば良さそう。

せっかくmariadbなので[client-mariadb]に設定してみる。

[client-mariadb]
prompt='\\U [\\d] \\r:\\m \\P>\\_'

mariadbに入ってみる。

$ mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 219742
Server version: 5.5.47-MariaDB MariaDB Server

Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.

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

lorentzca@localhost [(none)] 10:58 pm>

やったね!