MySQL:修改mysql提示符
如果不修改提示符,那么MySQL的提示符将永远是“mysql>”。而这其实是不易读的。
修改MySQL的提示符可以通过mysql的prompt参数修改。
关于Prompt的format string的完整列表可以通过man的帮助页获得:
1. man mysql
2. /prompt
3. n (查找下一个)
最终,你会得到下列信息:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
The prompt command reconfigures the default mysql> prompt. The string for defining the prompt can contain the following special sequences. +-------+------------------------------------------------+ |Option | Description | +-------+------------------------------------------------+ |\C | The current connection identifier (MySQL 5.7.6 | | | and up) | +-------+------------------------------------------------+ |\c | A counter that increments for each statement | | | you issue | +-------+------------------------------------------------+ |\D | The full current date | +-------+------------------------------------------------+ |\d | The default database | +-------+------------------------------------------------+ |\h | The server host | +-------+------------------------------------------------+ |\l | The current delimiter | +-------+------------------------------------------------+ |\m | Minutes of the current time | +-------+------------------------------------------------+ |\n | A newline character | +-------+------------------------------------------------+ |\O | The current month in three-letter format (Jan, | | | Feb, ...) | +-------+------------------------------------------------+ |\o | The current month in numeric format | +-------+------------------------------------------------+ |\P | am/pm | +-------+------------------------------------------------+ |\p | The current TCP/IP port or socket file | +-------+------------------------------------------------+ |\R | The current time, in 24-hour military time | | | (0-23) | +-------+------------------------------------------------+ |\r | The current time, standard 12-hour time (1-12) | +-------+------------------------------------------------+ |\S | Semicolon | +-------+------------------------------------------------+ |\s | Seconds of the current time | +-------+------------------------------------------------+ |\t | A tab character | +-------+------------------------------------------------+ |\U | | | | Your full user_name@host_name account | | | name | +-------+------------------------------------------------+ |\u | Your user name | +-------+------------------------------------------------+ |\v | The server version | +-------+------------------------------------------------+ |\w | The current day of the week in three-letter | | | format (Mon, Tue, ...) | +-------+------------------------------------------------+ |\Y | The current year, four digits | +-------+------------------------------------------------+ |\y | The current year, two digits | +-------+------------------------------------------------+ |\_ | A space | +-------+------------------------------------------------+ |\ | A space (a space follows the backslash) | +-------+------------------------------------------------+ |\' | Single quote | +-------+------------------------------------------------+ |\" | Double quote | +-------+------------------------------------------------+ |\\ | A literal "\" backslash character | +-------+------------------------------------------------+ |\x | | | | x, for any "x" not listed above | +-------+------------------------------------------------+ You can set the prompt in several ways: Use an environment variable. You can set the MYSQL_PS1 environment variable to a prompt string. For example: shell> export MYSQL_PS1="(\u@\h) [\d]> " Use a command-line option. You can set the --prompt option on the command line to mysql. For example: shell> mysql --prompt="(\u@\h) [\d]> " (user@host) [database]> Use an option file. You can set the prompt option in the [mysql] group of any MySQL option file, such as /etc/my.cnf or the .my.cnf file in your home directory. For example: [mysql] prompt=(\\u@\\h) [\\d]>\\_ In this example, note that the backslashes are doubled. If you set the prompt using the prompt option in an option file, it is advisable to double the backslashes when using the special prompt options. There is some overlap in the set of permissible prompt options and the set of special escape sequences that are recognized in option files. (The rules for escape sequences in option files are listed in Section 4.2.6, "Using Option Files".) The overlap may cause you problems if you use single backslashes. For example, \s is interpreted as a space rather than as the current seconds value. The following example shows how to define a prompt within an option file to include the current time in HH:MM:SS> format: [mysql] prompt="\\r:\\m:\\s> " Set the prompt interactively. You can change your prompt interactively by using the prompt (or \R) command. For example: mysql> prompt (\u@\h) [\d]>\_ PROMPT set to '(\u@\h) [\d]>\_' (user@host) [database]> (user@host) [database]> prompt Returning to default PROMPT of mysql> mysql> |
如上说明所示,你可以这样修改(方法之一):
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 35 36 37 38 39 40 41 42 43 |
[root@rhel71 ~]# cat ~/.bash_profile # .bash_profile # Get the aliases and functions if [ -f ~/.bashrc ]; then . ~/.bashrc fi # User specific environment and startup programs PATH=/mydata/mysql/scripts:/usr/local/mysql/bin:$PATH:$HOME/bin export PATH export MYSQL_PS1="(\u@\h) [\d]> " [root@rhel71 ~]# [root@rhel71 ~]# source ~/.bash_profile [root@rhel71 ~]# env | grep MYSQL MYSQL_PS1=(\u@\h) [\d]> [root@rhel71 ~]# [root@rhel71 ~]# mysqlplus.sh Login MySQL Service @ rhel71:3306 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 5 Server version: 5.7.7-rc-log Source distribution Copyright (c) 2000, 2015, 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 alienware; 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) [alienware]> exit Bye [root@rhel71 ~]# |
————————————————————————
Done。