Emacs how to use ssh tunnel to connect to remote MySQL

前端 未结 3 660
感动是毒
感动是毒 2021-02-06 12:18

I have a bunch of remote MySQL servers, that allow connection only from localhost. To connect to them I do the following:

ssh host
mysql -uuser -psecret -hhost.m         


        
3条回答
  •  一向
    一向 (楼主)
    2021-02-06 12:41

    Sql mode uses default-directory when it establishes the connection to the database, so if the variable is in TRAMP format, ssh (or whatever) will be used to connect to the remote host first, then use the database client locally. To automate that you can do something like

    (defadvice sql-mysql (around sql-mysql-around activate)
      "SSH to linux, then connect"
      (let ((default-directory "/ssh:host.myhost.com:"))
        ad-do-it))
    

    You can of course replace "/ssh:host.myhost.com:" with the function call that would ask you which host to connect, etc.

提交回复
热议问题