Archive for April 20th, 2011

Adding colour to your mysql prompt

Wednesday, April 20th, 2011

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.