Emacs 訪問 MySQL

來源:互聯網
上載者:User

用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))

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.