MySQL:Prompt 设置

默认情况连接到 mysql 库后不会显示当前连接的数据库名,数据库用户信息,在维护过程中不太方便,好在可以使用 prompt 属性进行设置。

/etc/my.cnf 添加以下

1
2
[mysql]  
prompt="u@h:d>"

备注:设置后重启 MySQL 服务。 u 表示用户名, h 表示主机名, d 表示当前数据库。

重启 MySQL 服务

1
2
3
[root@db1 bin]# /etc/init.d/mysql restart  
Shutting down MySQL. [OK ]
Starting MySQL.. [OK ]

连接测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[mysql@db1 tf]$ mysql  
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.6.20 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.

root@localhost:(none)>

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>

备注:注意上面的这行 , 正是我们在 /etc/my.cnf 设置的格式。

Prompt 更多设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
OptionDescription  
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 (023)
/r The current time, standard 12-hour time (112)
/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

原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/239596.html

(0)
上一篇 2022年2月12日
下一篇 2022年2月12日

相关推荐

发表回复

登录后才能评论