2

I can't find this information. I also use Grok, but his solution didn't work.

How can I add multiple accounts/credentials to different MySQL/MariaDB servers to be used with mysql command? Similar to .ssh/config and ssh.

Is it even possible? Can you have more than one client in ~/.my.cnf config?

1 Answer 1

2

Using strictly MySQL you can use the --login-path option

Read options from the named login path in the .mylogin.cnf login path file. A “login path” is an option group containing options that specify which MySQL server to connect to and which account to authenticate as. To create or modify a login path file, use the mysql_config_editor utility. See Section 6.6.7, “mysql_config_editor — MySQL Configuration Utility”.

MariaDB did not implement this argument, but you can use --defaults-group-suffix if you want to have a unique file centralizing all of your connections Let's say you have the following ~/.my.cnf

[client-foo] host = foo user = foo_user password = "foo_pass" [client-bar] host = bar user = bar_user password = "bar_pass" 

You can then connect to foo with

mariadb --defaults-group-suffix=-foo 

Please note that the syntax client- prefix in the group name is important. Also, if you want to have a file per connection, you can use --defaults-extra-file

Be aware, there are more aspects and differences between these two; everything is in the docs.

How can I add multiple accounts/credentials to different MySQL/MariaDB servers to be used with mysql command? Similar to .ssh/config and ssh.

You will not have the same level of customizability ~/.ssh/config offers but in the case you described it will work just fine.

2
  • If you complement the --defaults-group-suffix with shell aliases in '~/.{bash,zsh}rc` that's probably easy access. Commented yesterday
  • Sure, I didn't go that far since the OP seems to have experience with Linux/Unix systems, but yes, you can obviously add aliases for smoother usage. Commented yesterday

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.