7
3
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?
7
3
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?
11
Based on a discussion at http://bugs.mysql.com/bug.php?id=17627 I use the following method to automatically log into different mysql servers:
File /path/to/my-host1-cnf.txt
[client]
host="hostname1"
user="username1"
password="password1"
database="database1"
File /path/to/my-host2-cnf.txt
[client]
host="hostname2"
user="username2"
password="password2"
database="database2"
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 :-)
1This looks like it might be what I need. Thanks! – veilig – 2011-04-27T06:10:15.993
4
You can always create an aliases to it
alias db1='mysql -uUsername1 -pPasswordSecure1 -hHosname1 DatabaseName1'
alias db2='mysql -uUsername2 -pPasswordSecure2 -hHosname2 DatabaseName2'
etc..
And put them into your
.bash_aliases
.barsh_profile
or
.bash_rc
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 :(
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." https://dev.mysql.com/doc/refman/5.1/en/password-security-user.html
– geofflee – 2015-05-30T09:53:53.230Putting your password in plain text is never a good idea. Even if you secure your files it still executes as a command which will show up in ps aux
, your .bash_history, etc. – blockloop – 2018-01-10T14:39:00.330
1
See https://dba.stackexchange.com/questions/3889/is-it-possible-to-have-passwords-configured-per-database-or-per-host-in-my-cnf for an easier way to do this with the default
– Jim Stewart – 2017-08-04T16:39:21.030~/.my.cnf
file andmysql --defaults-group-suffix
.1do you connect to the mysql network port or ssh in and connect to the db locally? – RobotHumans – 2011-01-15T17:07:35.957