用Emacs访问MySQL好久了,最近因为换了单位,重新配置环境的时候居然花了一个多小时,特此记录。
1.Ubuntu下用sudo apt-get install 安装
libmysqlclient-dev 和 mysql-client-core-5.5
2.下载sql.el和mysql.el,并在~/.emacs文件中加载
http://www.emacswiki.org/emacs/sql.el
http://www.emacswiki.org/emacs/mysql.el
(load-file (expand-file-name "/opt/emacs_plugins/sql.el"))
(load-file (expand-file-name "/opt/emacs_plugins/mysql.el"))
3.如果你的mysql端口不是标准端口的话,需要用下面的命令在.emacs文件中设置
(setq sql-mysql-options (list "-P 6871"))
4.通过下面的命令设置两个连接mysql的常用帐号:
(setq sql-connection-alist
'((pool-a
(sql-product 'mysql)
(sql-server "ip1")
(sql-user "user1")
(sql-password "pwd1")
(sql-database "db1")
(sql-port 6871))
(pool-b
(sql-product 'mysql)
(sql-server "ip2")
(sql-user "user2")
(sql-password "pwd2")
(sql-database "db2")
(sql-port 3306))))
(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 mysql-a ()
(interactive)
(sql-connect-preset 'pool-a))
(defun mysql-b ()
(interactive)
(sql-connect-preset 'pool-b))
(责任编辑:IT) |