Automate MySQL login

When scripting MySQL from bash or when frequently accessing mysql command prompt it is useful not to have to enter the login credentials all the time. This however can be automated so you don’t have to do it.

In your home folder create .my.cnf file with the following content:

[client]
username=mysql_username
password=myslq_password

and that’s it. Now to access MySQL console just type in: myslq

So for example to see databases from bash we just run:

~$ echo show databases | mysql
Database
information_schema
dbCustomerInfo
mydb1
mydb2
mydb3
mysql
performance_schema
store

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × two =

This site uses Akismet to reduce spam. Learn how your comment data is processed.