【MySQL】命令行提示符参数prompt
在MySQL数据库默认情况下,mysql命令行提示符是mysql>,当执行SQL语句时,要么加上数据库名称,要么先得确认一下连接的是哪个数据库,相对麻烦一点点。在mysql配置文件my.cnf,可以通过mysql标签定义prompt参数进行提示符美化,可以做到一目了然。如下:
|
1 2 3 4 |
[root@node1 ~]# vi /etc/my.cnf [mysql] prompt=\U[\d]>\_ ......略 |
说明:
\U:当前用户名,带主机名
\d:默认数据库名字,尚未选定数据库,则是(none)
\_:空格字符
显示的效果如下:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[root@node1 ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2018, 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. root@localhost[(none)]> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed root@localhost[mysql]> |
参数prompt的选项如下:
\c:当前输入行数
\d:默认数据库名字,尚未选定数据库,则是(none)
\D:完整的日期和时间
\h:当前主机
\l:当前分隔符(从MySQL5.025/5.1.12起)
\m:分钟
\o:月份数字
\O:月份名称,3个字母
\p:当前端口号、套接字文件名、命名管道或共享内存的名字
\P:时间值am或pm标志
\r:小时(12小时)
\R:小时(24小时)
\s:秒
\S:分号
\t:制表符
\u:当前用户名,不带主机名
\U:当前用户名,带主机名
\v:服务器的版本号
\w:星期几,3个字母
\y:年(2位数字)
\Y:年(4位数字)
\’:单引号
\”:双引号
\_:空格字符
\:空格字符(这个转义序列是一个反斜线加一个空格)
\\:反斜线字符
\n:换行符
\x:字符x,x是内有上边列出现的任何字符