PhpRiot
News Archive
PhpRiot Newsletter
Your Email Address:

More information

Adding colour to your mysql prompt

Note: This article was originally published at Planet PHP on 20 April 2011.
Planet PHP

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) a 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.