Mysql command line automatic login

When connecting to mysql on a few different hosts it can save you time, by saving your mysql details in a file that will be used for login.

Create a file like

 vi ~/mysql_server1.txt 

Insert the following:

[client]
host="server1"
user="username"
password="password"
database="database" 

In the terminal run the following to use the contents of the file for login:

mysql --defaults-file="~/mysql_server1.txt" 

then you could even create a bash alias in ~/.bash_aliases

alias mysqlserver1='mysql --defaults-file="~/mysql_server1.txt"' 


Now all you need to run at the terminal is:

mysqlserver1 

June 27, 2011