I almost made a critical mistake on the production mysql database for one of my projects yesterday, which definitely would not have been a Good Thing if it had happened; even though I do have a custom prompt set up for mysql – when they’re all so similar you don’t always take heed.
So now, along with having the mysql prompt defined as prompt=’\h@\u (\d) > ‘ in the [mysql] section of my ~/.my.cnf file (so host, username and database name are included in the prompt), I have also installed rlwrap and set up an alias in my .bashrc:
if [ -x /usr/bin/rlwrap ]; then
alias mysql='/usr/bin/rlwrap -a -pGREEN /usr/bin/mysql'
fi
This displays the mysql prompt in green, after checking that rlwrap is available, which I have configured for my development environment only – now I just need to train myself to be extra careful for when the prompt isn’t coloured.
Very neat! Though, in the prompt specification for mysql, do you have the \h and \u the wrong way around?
Yes, I have; more efficiently it should be:
prompt=’\U (\d) > ‘
Just for the giggle factor, I’m defining it in my .bashrc now though:
if [ -x /usr/bin/rlwrap ]; then
alias mysql=”/usr/bin/rlwrap -a –prompt-colour=’1;33′ /usr/bin/mysql”
export MYSQL_PS1=”\U [`hostname`] (\d) > ”
else
export MYSQL_PS1=’\u@\h (\d) > ‘
fi
Due to running a lower version of rlwrap, I’ve had to define the prompt colour differently.