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

Why don't my .my.cnf settings work?

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

Problem

I have a .my.cnf file in my home directory on my desktop that includes:

[dbid]
user = myusername
password = mypassword
database = dbname
host = server.location.com


If I recall correctly, before upgrading from Ubuntu 10.04 to 11.04, I was able to use the command

mysql dbid


To connect directly to the database

But today I get this error:

ERROR 1049 (42000): Unknown database 'dbname'


Have I done something wrong?

Solution

I'm not sure how your previous .my.cnf used to work, and I actually have never used these files before (mainly because I didn't know about them). So after a bit of research, I found this link and came up with the following ~/.my.cnf that worked for me:

[clientdbid]
password = mypass
database = dbname
host = server.location.com


and the command that reads it:

mysql --defaults-group-suffix=dbid


A couple things to point out (highlights from the article linked):

  • group has to be preceded by 'client' to be read by mysql



  • has to go after any [client] groups, otherwise it will be overridden



I tested this on mysql 5.5 on a Mac, worked great. And now that I know about them, I will use them!

UPDATE
After I set this up, I realized that the command line mysql --defaults-group-suffix=dbid was a little hefty. So as added bonus, assuming you're running Linux/Mac/Etc do this:

echo 'alias mysql_dbid="mysql --defaults-group-suffix=dbid"' >> ~/.profile


Where dbid is the name of your suffix group.

Code Snippets

[clientdbid]
password = mypass
database = dbname
host = server.location.com
mysql --defaults-group-suffix=dbid
echo 'alias mysql_dbid="mysql --defaults-group-suffix=dbid"' >> ~/.profile

Context

StackExchange Database Administrators Q#2820, answer score: 27

Revisions (0)

No revisions yet.