Speeding up MySQL CLI workflow with .my.cnf

Posted in Articles on Oct 10, 2015

Hi all,

I've got a quick tip for you today. I thought it to be pretty common knowledge, but I'm surprised how many haven't picked it up, so here it is!

I work in Vagrant a lot, often on a single app with its own database, and dropping in and out of MySQL can be a bit of a pain. There is a solution to this though - an optional file that sits in your home directory called .my.cnf. This is basically just an override file for client settings in /etc/my.cnf. The way I usually configure it is to auto-fill my username, password and the database name I'm working on, meaning instead of going through the rigmarole of typing mysql -u root -p db_name, I can just type mysql.

The file should look as follows:


It really is as simple as that. Now whenever you're logged in as the user who has this file in place, you can just type mysql to get querying!