合 MySQL修改提示符(prompt)
MySQL修改提示符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 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修改提示符:
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 | --修改提示符 set linesize 9999 pagesize 9999 set sqlprompt "USER'@'CONNECT_IDENTIFIER> " cat >> $ORACLE_HOME/sqlplus/admin/glogin.sql << "EOF" set linesize 9999 pagesize 9999 set sqlprompt "USER'@'CONNECT_IDENTIFIER> " EOF set time on; set line 9999 set pagesize 9999; set timing on; set sqlprompt "USER'@'CONNECT_IDENTIFIER> " set echo on; set time on; SET 99999999; SET CHUNKSIZE 1000000; set timing on; set serveroutput on size 1000000; set sqlblanklines on; set linesize 800; set pagesize 50000; set sqlprompt "USER'@'CONNECT_IDENTIFIER> " host color 02 alter session set NLS_DATE_FORMAT='YYYY-MM-DD HH24:MI:SS'; set errorlogging on table lhr.sperrorlog; set errorlogging on identifier LHR_SESSION |
其它
MySQL 客户端的默认提示符是 "mysql>",基本上没什么实际作用。其实可以修改这个提示符,让它显示一些有用的信息,例如当前所在的数据库等。修改方法有四种,其中前两种只对当前连接有效,后两种则对所有连接有效。
1、连接客户端时通过参数指定。
mysql --prompt="(\u@\h) [\d]> "
这样提示符就会变成 (user@host) [database]>。其中常用的字符参数有:
- \d: 当前数据库
- \h: 服务器地址
- \u: 用户名
还有更多可以可以参考官方文档 4.5.1.2. mysql Commands
2、连接上客户端后,通过 prompt 命令修改。
- prompt (\u@\h) [\d]>
3、在 MySQL 的配置文件中配置。
- [mysql]
- prompt=(\u@\h) [\d]>\_
4、通过环境变量配置。
- export MYSQL_PS1="(\u@\h) [\d]> "
官方文档
官方文档:https://dev.mysql.com/doc/refman/5.7/en/mysql-commands.html
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:
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 33 34 | 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.
help [arg], \h [arg], \? [arg], ? [arg]
Display a help message listing the available mysql commands.
If you provide an argument to the help command, mysql uses it as a search string to access server-side help from the contents of the MySQL Reference Manual. For more information, see Section 4.5.1.4, “mysql Server-Side Help”.
charset charset_name, \C charset_name
Change the default character set and issue a SET NAMES statement. This enables the character set to remain synchronized on the client and server if mysql is run with auto-reconnect enabled (which is not recommended), because the specified character set is used for reconnects.
clear, \c
Clear the current input. Use this if you change your mind about executing the statement that you are entering.
connect [db_name host_name]], \r [db_name host_name]]
Reconnect to the server. The optional database name and host name arguments may be given to specify the default database or the host where the server is running. If omitted, the current values are used.
delimiter str, \d str
Change the string that mysql interprets as the separator between SQL statements. The default is the semicolon character (;).
The delimiter string can be specified as an unquoted or quoted argument on the delimiter command line. Quoting can be done with either single quote ('), double quote ("), or backtick (`) characters. To include a quote within a quoted string, either quote the string with a different quote character or escape the quote with a backslash () character. Backslash should be avoided outside of quoted strings because it is the escape character for MySQL. For an unquoted argument, the delimiter is read up to the first space or end of line. For a quoted argument, the delimiter is read up to the matching quote on the line.
mysql interprets instances of the delimiter string as a statement delimiter anywhere it occurs, except within quoted strings. Be careful about defining a delimiter that might occur within other words. For example, if you define the delimiter as X, you will be unable to use the word INDEX in statements. mysql interprets this asINDE followed by the delimiter X.
When the delimiter recognized by mysql is set to something other than the default of ;, instances of that character are sent to the server without interpretation. However, the server itself still interprets ; as a statement delimiter and processes statements accordingly. This behavior on the server side comes into play for multiple-statement execution (see Section 27.8.17, “C API Support for Multiple Statement Execution”), and for parsing the body of stored procedures and functions, triggers, and events (see Section 23.1, “Defining Stored Programs”).
edit, \e
Edit the current input statement. mysql checks the values of the EDITOR and VISUAL environment variables to determine which editor to use. The default editor is viif neither variable is set.
The edit command works only in Unix.
ego, \G
Send the current statement to the server to be executed and display the result using vertical format.
exit, \q
Exit mysql.
go, \g
Send the current statement to the server to be executed.
nopager, \n
Disable output paging. See the description for pager.
The nopager command works only in Unix.
notee, \t
Disable output copying to the tee file. See the description for tee.
nowarning, \w
Disable display of warnings after each statement.
pager [command], \P [command]
Enable output paging. By using the --pager option when you invoke mysql, it is possible to browse or search query results in interactive mode with Unix programs such as less, more, or any other similar program. If you specify no value for the option, mysql checks the value of the PAGER environment variable and sets the pager to that. Pager functionality works only in interactive mode.
本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信dbaup66,谢谢!