Blog
June 27, 2015 Marie H.

MySQL Tip: CLI authentication

MySQL Tip: CLI authentication

Photo by <a href="https://unsplash.com/@zulfugarkarimov?utm_source=cloudista&utm_medium=referral" target="_blank" rel="noopener">Zulfugar Karimov</a> on <a href="https://unsplash.com/?utm_source=cloudista&utm_medium=referral" target="_blank" rel="noopener">Unsplash</a>

Quick tip to those new to managing a the MySQL database or even those that have been doing it for years. You do not need to authenticate with your username and password everytime.

In order to skip this all you need to do is setup $HOME/.my.cnf as such:

[client]
user=root
password=ubersecurepassword

Then when you enter the MySQL console all you need to do is run:

[root@ip-172-31-41-252 modern]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 647
Server version: 5.6.25 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 mysql>

and tada no need to mess with passing arguments for username and password.