数据库
首页 > 数据库> > MySQL修改提示符(prompt)

MySQL修改提示符(prompt)

作者:互联网

MySQL修改提示符(prompt)      

   


 export MYSQL_PS1="(\u@\h) [\d]> "  
prompt (\u@\h) [\d]>\_
prompt (\U) [\d]>\_
prompt \u@\d>\_  
prompt \R:\m:\s>\_  

prompt (\u@\h) [\d] \R:\m:\s>\_  
 
 
---------------------------------------------------------------------------  
 mysql> prompt (\u@\h) [\d] \R:\m:\s>\_  
PROMPT set to '(\u@\h) [\d] \R:\m:\s>\_'  
(root@localhost) [lhrdb] 23:10:37>   
 
 


Oracle修改提示符:   
 
  --$ORACLE_HOME/sqlplus/admin/glogin.sql  

 
 --修改提示符  
set linesize 9999 pagesize 9999  
set sqlprompt "_USER'@'_CONNECT_IDENTIFIER> "  


 
 




 

MySQL 客户端的默认提示符是 "mysql>",基本上没什么实际作用。其实可以修改这个提示符,让它显示一些有用的信息,例如当前所在的数据库等。修改方法有四种,其中前两种只对当前连接有效,后两种则对所有连接有效。

 

1、连接客户端时通过参数指定。

  1. mysql --prompt="(\u@\h) [\d]> "  

 这样提示符就会变成 (user@host) [database]>。其中常用的字符参数有:

 

还有更多可以可以参考官方文档 4.5.1.2. mysql Commands

 

2、连接上客户端后,通过 prompt 命令修改。

  1. prompt (\u@\h) [\d]>  

 

3、在 MySQL 的配置文件中配置。


  1. [mysql]  
  2. prompt=(\\u@\\h) [\\d]>\\_  

 

4、通过环境变量配置。


  1. export MYSQL_PS1="(\u@\h) [\d]> "  

 
 
 
 




官方文档:  https://dev.mysql.com/doc/refman/5.7/en/mysql-commands.html  
 
 

4.5.1.2 mysql Commands

mysql sends each SQL statement that you issue to the server to be executed. There is also a set of commands that mysql itself interprets. For a list of these commands, type help or \h at the mysql> prompt:

mysql> help


List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given
               outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing
               binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
resetconnection(\x) Clean session context.


For server side help, type 'help contents'

 


 

If mysql is invoked with the --binary-mode option, all mysql commands are disabled except charset and delimiter in non-interactive mode (for input piped to mysqlor loaded using the source command).

Each command has both a long and short form. The long form is not case sensitive; the short form is. The long form can be followed by an optional semicolon terminator, but the short form should not.

The use of short-form commands within multiple-line /* ... */ comments is not supported.

Here are a few tips about the pager command:

You can also combine the tee and pager functions. Have a tee file enabled and pager set to less, and you are able to browse the results using the less program and still have everything appended into a file the same time. The difference between the Unix tee used with the pager command and the mysql built-in tee command is that the built-in tee works even if you do not have the Unix tee available. The built-in tee also logs everything that is printed on the screen, whereas the Unix tee used withpager does not log quite that much. Additionally, tee file logging can be turned on and off interactively from within mysql. This is useful when you want to log some queries to a file, but not others.

 

The prompt command reconfigures the default mysql> prompt. The string for defining the prompt can contain the following special sequences.

OptionDescription
\CThe current connection identifier (MySQL 5.7.6 and up)
\cA counter that increments for each statement you issue
\DThe full current date
\dThe default database
\hThe server host
\lThe current delimiter
\mMinutes of the current time
\nA newline character
\OThe current month in three-letter format (Jan, Feb, …)
\oThe current month in numeric format
\Pam/pm
\pThe current TCP/IP port or socket file
\RThe current time, in 24-hour military time (0–23)
\rThe current time, standard 12-hour time (1–12)
\SSemicolon
\sSeconds of the current time
\tA tab character
\U

Your full user_name@host_name account name

\uYour user name
\vThe server version
\wThe current day of the week in three-letter format (Mon, Tue, …)
\YThe current year, four digits
\yThe 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

You can set the prompt in several ways:

 
 
 

标签:set,prompt,MySQL,current,command,file,mysql,提示符
来源: https://blog.51cto.com/lhrbest/2698367