HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlCritical

Is it possible to have passwords configured per database or per host in .my.cnf

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
perpasswordscnfdatabasepossiblehostconfiguredhave

Problem

I have the following in my ~/.my.cnf

[client]
password="somepass"


but this is not the password I use for every user@host/database I connect to. Is there some way to specify in the config different passwords for different things so I don't have to type them in?

Solution

As I answered here, you can add a section for each user/host/db you connect to using the syntax in your ~/.my.cnf:

[clienthost1]   # Note: client + host1
user=myuser
password=mypass
database=dbname
host=server.location.com


Once this is in your user's .my.cnf, you can utilize it by doing this on a command line:

$ mysql --defaults-group-suffix=host1

Code Snippets

[clienthost1]   # Note: client + host1
user=myuser
password=mypass
database=dbname
host=server.location.com
$ mysql --defaults-group-suffix=host1

Context

StackExchange Database Administrators Q#3889, answer score: 83

Revisions (0)

No revisions yet.