How can I configure my MariaDB client (mysql) so that I don't have to enter a password to connect, regardless of which host I am connecting to?

I can't just put a password in the [client] section of ~/.my.cnf because that would apply all hosts.

For example, I'd like to be able to connection with mysql -h myhost mydatabase, ie. without specifying username or password. Even better would be the ability to specify a "host alias" instead of the actual (awkwardly long) hostname.

It sounds like this is possible in MySQL with the mysql-config-editor but MariaDB does not have this feature.


In ~/.my.cnf make sections like:



Then make an alias (assuming Linux-like OS - depending on shell, you can perhaps put the alias in ~/.bashrc_local):

alias mysql="mysql --defaults-group-suffix=\`hostname --short\`"

Now you can connect without specifying the password to any of the hosts for which you have stored the credentials in ~/.my.cnf. (These would be my_host_name_1 and my_host_name_2 in my example above.)

| improve this answer | |
  • Clever. A bit awkward, but it meets my needs. Thanks. – Jared Beck Feb 2 '18 at 23:39
  • sounds similar to the answer below, very similar. – andres Feb 3 '18 at 14:25

I have used the mysql_config_editor years ago it works, very well. And it is an option for you. other options will be to create some alias as long as you are using linux/mac: something like alias mysqlserver1='mysql -ulalala -plalalapass -hserver1'

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.