Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to log into multiple MYSQL DB's on different hosts via mysql cli. is it possible to save these logins so I don't have to trackdown/remember the credentials?

share|improve this question
do you connect to the mysql network port or ssh in and connect to the db locally? – RobotHumans Jan 15 '11 at 17:07
up vote 4 down vote accepted

Based on a discussion at I use the following method to automatically log into different mysql servers:

File /path/to/my-host1-cnf.txt


File /path/to/my-host2-cnf.txt


Connect to host1, database1 with saved credentials above:

mysql --defaults-file="/path/to/my-host1-cnf.txt"

Connect to host2, database2 with saved credentials above:

mysql --defaults-file="/path/to/my-host2-cnf.txt"

Hope this helps :-)

share|improve this answer
This looks like it might be what I need. Thanks! – veilig Apr 27 '11 at 6:10

You can always create an aliases to it

alias db1='mysql -uUsername1 -pPasswordSecure1 -hHosname1 DatabaseName1'
alias db2='mysql -uUsername2 -pPasswordSecure2 -hHosname2 DatabaseName2'


And put them into your





But this doesn't solve the security issue! Even if you put "good" permission on your bash files it doesn't mean it isn't plain text :(

share|improve this answer
This is not safe! "This is convenient but insecure. On some systems, your password becomes visible to system status programs such as ps that may be invoked by other users to display command lines." – geofflee May 30 '15 at 9:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .