MySQL终端显示当前用户名、服务器、和数据库

MySQL终端默认是这样子的,比较简陋:

➔ mysql
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 150
Server version: 5.6.47-log Homebrew

Copyright (c) 2000, 2020, 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.
mysql>

觉得mysql>太简单了,我想让他显示更多的信息,就像平时我会用oh-my-zsh修改本地的shell那样,比如,这是我终端的提示符:

jake in Macintosh at Code/foo-poject on jake-v2.13 [!?$]
➔

可以显示当前用户名,目录,git版本等等信息。

方法很简单,设置一个环境变量即可:

export MYSQL_PS1="\u@\h [\d]> "

再次尝试:

➔ mysql
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 151
Server version: 5.6.47-log Homebrew

Copyright (c) 2000, 2020, 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)]> use performancenet;
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 [performancenet]>

现在提示符部分变得丰富了?,如果想永久生效,需要将export MYSQL_PS1="\u@\h [\d]> "这行命令加入到你的~/.bashrc(或者~/.zshrc)文件中。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注