Bug #17627 .my.cnf: Multiple host, user, pass, db entries
Submitted: 21 Feb 2006 20:12 Modified: 23 Nov 2006 20:47
Reporter: Olaf van der Spek (Basic Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S4 (Feature request)
Version:* OS:Any (*)
Assigned to: CPU Architecture:Any

[21 Feb 2006 20:12] Olaf van der Spek
Description:
Hi,

At the moment you can only put a single host, user, pass, db entry in .my.cnf.
Could you remove this limitation and support multiple entries?

How to repeat:
-
[6 Mar 2006 12:15] Valeriy Kravchuk
Please, read about MySQL Instance Manager (http://dev.mysql.com/doc/refman/5.0/en/instance-manager-configuration-files.html). Looks like it does exactly what you want.
[6 Mar 2006 12:20] Olaf van der Spek
No, that's for servers. My feature request is for clients, sorry for not being clear about that.
[6 Mar 2006 12:43] Valeriy Kravchuk
Thank you for the clarification. Make copiles (or symlinks) to mysql client: mysql1, mysql2 etc. Then try to use:

[mysql1]
...
[mysql2]
...

sections in your my.cnf. Will it work for you?
[6 Mar 2006 12:46] Olaf van der Spek
I'm currently using [client] instead of [mysql]. It should work for both the mysql and mysqldump apps (and probably others too).
I don't think symlinks are a good solution.
It should be possible to do mysql --database <database> and have the client lib read the right password (and host/user if not provided) from the .my.cnf file.
[6 Mar 2006 12:51] Valeriy Kravchuk
OK. Now we know exactly what is requested. It will surely be useful and convenient feature.
[14 Apr 2006 13:05] Sergei Golubchik
Try the option --default-group-suffix
Unfortunately it's still not documented, see bug#19103
[15 Apr 2006 17:47] Olaf van der Spek
That would require support from all clients apps. It would be much nicer if the client library could automatically fetch the password (and other fields) based on host, user and db.
[26 May 2006 20:00] Valeriy Kravchuk
OK, if no workarounds proposed are useful for you, let's call this a reasonable feature request.
[23 Nov 2006 20:38] Wolfram Schlich
What's the current status of this feature?

As to the details of the my.cnf format, I could imagine something similar
to the OpenSSH ssh_config format for host-specific configuration:

[client]
host = foo
user = foo
pass = cat

host = bar
user = bar
pass = dog

host = *
user = defaultuser
pass = defaultpass

All user, pass and other values would be specific to a preceding host value (if any). A host value of * could be used to specify default settings.
[23 Nov 2006 20:44] Wolfram Schlich
How would the current implementation of the mysql client library deal with a my.cnf in my suggested format? Would it use the value of the first or the last entry of a single key? Or would it fail to parse the config at all?
[23 Nov 2006 20:47] Olaf van der Spek
I think it'll use the last entry.
But why don't you test that?
[23 Nov 2006 21:06] Wolfram Schlich
Oh, well, I thought it would be better if someone who is "into the code"
would give a definitive answer to that question instead of me just trying
or digging for the respective lines of code ;)
[26 Nov 2006 17:15] Sergei Golubchik
it'll use the last entry
[18 Feb 2008 17:16] Christian Hansen
Hi,
i have the same Problem is there any new information or solution ?
with regards
Christian Hansen
[2 Jul 2008 17:30] Tong Narak
I want these feature too.

[client1]

[client2]

[client3]
[2 Jul 2008 17:52] Tong Narak
to backup automate mysqldump

user options --defaults-extra-file=path/to/file.cnf

[client]
host     = localhost
user     = username
password = topsecret
[2 Jul 2008 18:39] Tong Narak
Automate backup MySQL with mysqldump without -p

   1. Create a text file, example "1.cnf".

   2. Add the following example data:

      [client]
      host = localhost
      user = user1
      pass = pass1

   3. Don't forget to set permission.

      chmod 600 1.cnf

   4. Add cron job will the following example command line:

      mysqldump --defaults-extra-file=/home/tong/1.cnf --opt -Q database1 > database1.sql

      Note: --defaults-extra-file should be at the first argument.
[30 May 2012 16:37] Richard Byrd
Did anything ever happen with this feature request?  It'd be quite helpful.
[23 Sep 2012 6:49] JP Lew
bump for this feature, it would be really cool