When I type mysql dbname
at the bash prompt, I automatically connect to the database dbname
with the username
, password
, and host
information included in my .my.cnf
file.
When I use M-x sql-mysql
in emacs, I am asked for all of this information again.
Is there a way that I can get emacs sql mode to use the information in my .my.cnf
file?
Just hit return, it's picked up by default.
Sure it's possible. It's quite involved though.
Roughly, the steps are:
sql-connection-alist
sql-connection-alist
M-x sql-connect
(which auto-completes!)The following code also includes a .pgpass parser, just in case. You'll notice the implementation is simpler.
With the following
.my.cnf
:Executing the expression
(mycnf-to-sql-connection (parse-mycnf-hosts "~/.my.cnf"))
gives me (pretty printed by hand):Finally, instead of using
M-x sql-mysql
, useM-x sql-connect
and you'll be able to connect using the alias, with auto-completion.I don't think that this is possible but you can set such stuff in the mode configuration itself:
Have a look at this article for more info.