MySQL | Changing the MySQL command line prompt
Having recently debugged a MySQL replication setup, I was having a hard time keeping track of which database was open in which mysql command line client, as since before the start of time the prompt has been a very terse mysql> , giving no visual clue to which database is currently the default.
Fortunately, beginning with release 4.0.2 MySQL now provides a little-known option to set the prompt in a manner similar to that used in UNIX shells.
The prompt can be set directly with the instruction prompt or before starting the mysql client using the environment variable MYSQL_PS1. There is a large selection of command sequences to dynamically include information about the database and current environment (see link below for the full list).
For example - \u@\d > shows the current MySQL username and database:
mysql> prompt u@\d >
PROMPT set to '\u@\d > '
me@test_db >
(Typing prompt without any arguments resets the prompt to the default mysql>). Using MYSQL_PS1 enables the inclusion of server environment variables as well, providing a greater range of options; I use export MYSQL_PS1="$HOST:\\d> " which inserts the actual server name (the prompt option \h will show localhost unless you connect via an external network interface).
To keep your changes permanent, store them in an option file such as my.cnf or the .my.cnf file in your home directory. On a UNIX system it's easy to the MYSQL_PS1 in a shell configuration file such as /etc/profile or .bashrc. In all cases remember to escape backslashes with another backslash.
Reference: http://dev.mysql.com/doc/mysql/en/mysql_Commands.html