MySQL.rc Configuring Your MySQL Client

I recently wanted to customize the SQL command line prompt so that I'd know the database server to which I was connected. Previously, I'd been using the --prompt option when connecting (e.g. alias dev-db='mysql -h dev-db --prompt "dev-db-mysql>"';), but that gets maintenance heavy as I add more and more databases to my shortcuts.

I resolved to find a more generic way. I tried all sorts of google searches, all of which came up unhelpful. With no choice left, I headed to the MySQL docs. After some clicking around, I came upon this page, http://dev.mysql.com/doc/refman/5.0/en/mysql-commands.html.

This is great news! Apparently, I have several options.
  • /etc/my.cnf - Globally change the mysql client for all users of a given machine
  • ~/.my.cnf - Change for just me on a given machine
  • export $MYSQL_PS1 - Change just my prompt without requiring any new files
Since all of the machines I use are already controlled with puppet, it was a simple change for me to add a definition for $MYSQL_PS1 in my profile.

Comments

Recent posts