Quick login to Mysql on Ubuntu

~/.my.cnf

Create the file in your favourite editor.

vim ~/.my.cnf

Add the following content (adjust for YOUR user.)

[mysql]
  user=YOURUSER
  password=YOURPASS
  host=127.0.0.1

[mysqldump]
  user=YOURUSER
  password=YOURPASS
  host=127.0.0.1

Set the file permissions:

chmod 600 ~/.my.cnf

Now you can login to Mysql using:

mysql

Or dump a database with:

mysqldump --all-databases --single-transaction --events --routines --triggers | gzip > ./all_databases.sql.gz

Bonus

If you provision with Ansible, Chef or Puppet, you can generate this file for each of your server users or deployers using secure vault encryption for transmission to server. Be sure to follow best practice security if you do it this way.

Schedule a call with Stuntrocket

Schedule a free call -let's talk about your project

We'll talk for around 10 minutes on phone or video about what you're looking to do. Free, no sales.