MySQL修改提示符(prompt)

0    188    1

Tags:

👉 本文共约6765个字,系统预计阅读时间或需26分钟。

MySQL修改提示符


Oracle修改提示符:

其它

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

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

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

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

  • \d: 当前数据库
  • \h: 服务器地址
  • \u: 用户名

还有更多可以可以参考官方文档 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

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:

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.

标签:

Avatar photo

小麦苗

学习或考证,均可联系麦老师,请加微信db_bao或QQ646634621

您可能还喜欢...

发表回复