分类: Mysql/postgreSQL
2013-04-02 09:57:56
原文地址:修改MySQL命令提示符 作者:ning_lianjie
当前session可以直接用prompt修改
mysql> prompt \D
PROMPT set to '\D'
Mon May 30 12:31:28 2011
mysql>prompt \u@\h \d \r:\m:\s>
PROMPT set to '\u@\h \d \r:\m:\s>'
root@localhost (none) 12:50:40>
还可以在my.cnf配置文件中[mysql]添加(注意不是[mysqld]),加在配置文中后,不需要重启mysql,退出session,重新登录即可。
如果在my.cnf配置文件中最好用\\,避免转义带来的问题。
[mysql]
prompt=\\u@\\h \\d \\r:\\m:\\s>
关于\U(\h),The server host的一些测试
msyql.user表如下
+-------------+-------------+
| user | host |
+-------------+-------------+
| replication | % |
| root | 127.0.0.1 |
| | localhost |
| root | localhost |
| | ora01.dh.cn |
| repli | ora01.dh.cn |
| root | ora01.dh.cn |
+-------------+-------------+
# mysql -h192.168.60.134 -P3308
mysql> prompt \U
PROMPT set to '\U'
root@ora01.dh.cn
# mysql -h127.0.0.1 -P3308
mysql> prompt \U
PROMPT set to '\U'
root@localhost
# mysql -S mysql3.sock
mysql> prompt \U
PROMPT set to '\U'
root@localhost
结论,提示符中的h参数,与mysql连接时的socket或者tcp有关系。
shell>man mysql
+-------+--------------------------------------------------+
|Option | Description |
+-------+--------------------------------------------------+
|\c | A counter that increments for each statement you |
| | issue |
+-------+--------------------------------------------------+
|\D | The full current date |
+-------+--------------------------------------------------+
|\d | The default database |
+-------+--------------------------------------------------+
|\h | The server host |
+-------+--------------------------------------------------+
|\l | The current delimiter |
+-------+--------------------------------------------------+
|\m | Minutes of the current time |
+-------+--------------------------------------------------+
|\n | A newline character |
+-------+--------------------------------------------------+
|\O | The current month in three-letter format (Jan, |
| | Feb, ...) |
+-------+--------------------------------------------------+
|\o | The current month in numeric format |
+-------+--------------------------------------------------+
|\P | am/pm |
+-------+--------------------------------------------------+
|\p | The current TCP/IP port or socket file |
+-------+--------------------------------------------------+
|\R | The current time, in 24-hour military time |
| | (0–23) |
+-------+--------------------------------------------------+
|\r | The current time, standard 12-hour time (1–12) |
+-------+--------------------------------------------------+
|\S | Semicolon |
+-------+--------------------------------------------------+
|\s | Seconds of the current time |
+-------+--------------------------------------------------+
|\t | A tab character |
+-------+--------------------------------------------------+
|\U | |
| | Your full user_name@host_name account |
| | name |
+-------+--------------------------------------------------+
|\u | Your user name |
+-------+--------------------------------------------------+
|\v | The server version |
+-------+--------------------------------------------------+
|\w | The current day of the week in three-letter |
| | format (Mon, Tue, ...) |
+-------+--------------------------------------------------+
|\Y | The current year, four digits |
+-------+--------------------------------------------------+
|\y | The current year, two digits |
+-------+--------------------------------------------------+
|\_ | A space |
+-------+--------------------------------------------------+
|\ | A space (a space follows the backslash) |
+-------+--------------------------------------------------+
|\′ | Single quote |
+-------+--------------------------------------------------+
|\" | Double quote |
+-------+--------------------------------------------------+
|\\ | A literal “\” backslash character |
+-------+--------------------------------------------------+
|\x | |
| | x, for any “x” not listed above |
+-------+--------------------------------------------------+