参考官方资料:/doc/refman/5.7/en/mysql-commands.html
设置prompt主要是方便搞清楚生产系统中登录的是哪个库,哪个用户,防止误操作。
常用选项如下,其它选项详见官方文档:
OptionDescription\cA counter that increments for each statement you issue\DThe full current date\dThe default database\hThe server host\mMinutes of the current time\RThe current time, in 24-hour military time (0–23)\sSeconds of the current time\UYour full user_name@host_name account name\uYour user name\_A space\ A space (a space follows the backslash)\'Single quote\"Double quote\\A literal \ backslash character
官方给出了共4种方式去设置:
1).推荐,直接在mysql命令窗口中设置
mysql> prompt \R:\m:\s \U[\d]>如果要取消提示,敲prompt命令即可
2).设置MYSQL_PS1环境变量
shell> export MYSQL_PS1="(\u@\h) [\d]> "
3).启动mysql时,使用–prompt参数
shell> mysql --prompt="(\u@\h) [\d]> "
4).prompt参数写入参数文件,比如/etc/f
[mysql]prompt=(\\u@\\h) [\\d]>\\_