Although graphical clients are preferred when accessing MySQL databases, for many users the mysql command line client is the first choice when connecting to the MySQL server. And many times this is the only option available when you are accessing remote machines through SSH.
The default mysql prompt is the simple:
Nice and simple, but if you have multiple mysql client windows open it can be a little harder to know which window is connected to which user and database. Changing the prompt to display the database and user makes it easier to quickly tell which window is connected to which client and database.
Changing the mysql prompt
To change the prompt open your MySQL my.cnf (or my.ini if you are using Windows) and add the following line in the [mysql] section. If the file does not have one, create it by adding the following line.
After the above line add the following option.
The ‘\u’ and ‘\h’ display the username and hostname respectively. The ‘\d’ displays the default database selected. Restarting the client will display the changed prompt, the following is what it looks like on my machine. ‘wordpress’ is my default database.
If you do not want to make changes to the my.ini file or are unable to do so, you can also change the prompt interactively as shown below.
shell> mysql --prompt="\u@\h:[\d]>\_" -uUSERNAME -p
List of options
The ‘prompt’ parameter supports many options, a complete list is shown in the following table.
|A counter that increments for each statement you issue|
|The full current date|
|The default database|
|The server host|
|The current delimiter (new in 5.0.25)|
|Minutes of the current time|
|A newline character|
|The current month in three-letter format (Jan, Feb, …)|
|The current month in numeric format|
|The current TCP/IP port or socket file|
|The current time, in 24-hour military time (0–23)|
|The current time, standard 12-hour time (1–12)|
|Seconds of the current time|
|A tab character|
|Your full user_name@host_name account name|
|Your user name|
|The server version|
|The current day of the week in three-letter format (Mon, Tue, …)|
|The current year, four digits|
|The current year, two digits|
|A space (a space follows the backslash)|
|A literal “|
|x, for any ‘x’ not listed above|