patternsqlMajor
Why don't my .my.cnf settings work?
Viewed 0 times
whysettingscnfworkdon
Problem
I have a .my.cnf file in my home directory on my desktop that includes:
If I recall correctly, before upgrading from Ubuntu 10.04 to 11.04, I was able to use the command
To connect directly to the database
But today I get this error:
Have I done something wrong?
[dbid]
user = myusername
password = mypassword
database = dbname
host = server.location.comIf I recall correctly, before upgrading from Ubuntu 10.04 to 11.04, I was able to use the command
mysql dbidTo 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:
and the command that reads it:
A couple things to point out (highlights from the article linked):
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
Where
[clientdbid]
password = mypass
database = dbname
host = server.location.comand the command that reads it:
mysql --defaults-group-suffix=dbidA 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"' >> ~/.profileWhere
dbid is the name of your suffix group.Code Snippets
[clientdbid]
password = mypass
database = dbname
host = server.location.commysql --defaults-group-suffix=dbidecho 'alias mysql_dbid="mysql --defaults-group-suffix=dbid"' >> ~/.profileContext
StackExchange Database Administrators Q#2820, answer score: 27
Revisions (0)
No revisions yet.