合 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]]
本人提供Oracle(OCP、OCM)、MySQL(OCP)、PostgreSQL(PGCA、PGCE、PGCM)等数据库的培训和考证业务,私聊QQ646634621或微信db_bao,谢谢!