如何使用emacs sql-mode来使用mysql配置文件(.my.cnf)? [英] How can I get emacs sql-mode to use the mysql config file (.my.cnf)?

查看:187
本文介绍了如何使用emacs sql-mode来使用mysql配置文件(.my.cnf)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在bash提示符下键入 mysql dbname 时,我自动连接数据库 dbname 用户名密码主机信息包含在我的 .my.cnf 文件。

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.

当我使用 Mx sql-mysql 在emacs,我被要求所有这些信息。

When I use M-x sql-mysql in emacs, I am asked for all of this information again.

有没有办法,我可以得到emacs sql模式使用我的 .my.cnf 文件?

Is there a way that I can get emacs sql mode to use the information in my .my.cnf file?

推荐答案

我不认为这是可能的您可以在模式配置中设置这些内容:

I don't think that this is possible but you can set such stuff in the mode configuration itself:

(setq sql-connection-alist
'((pool-a
(sql-product 'mysql)
(sql-server "1.2.3.4")
(sql-user "me")
(sql-password "mypassword")
(sql-database "thedb")
(sql-port 3306))
(pool-b
(sql-product 'mysql)
(sql-server "1.2.3.4")
(sql-user "me")
(sql-password "mypassword")
(sql-database "thedb")
(sql-port 3307))))

(defun sql-connect-preset (name)
  "Connect to a predefined SQL connection listed in `sql-connection-alist'"
  (eval `(let ,(cdr (assoc name sql-connection-alist))
    (flet ((sql-get-login (&rest what)))
      (sql-product-interactive sql-product)))))

(defun sql-pool-a ()
  (interactive)
  (sql-connect-preset 'pool-a))

看看这篇文章了解更多信息。

这篇关于如何使用emacs sql-mode来使用mysql配置文件(.my.cnf)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆